gpt4 book ai didi

c - 错误: L6218E: Undefined symbol three()

转载 作者:行者123 更新时间:2023-11-30 15:00:39 26 4
gpt4 key购买 nike

[编辑:问题是有缺陷的,我描述为“main.c”的文件实际上是“main.cpp”,这就是为什么我遇到问题,从 C++ 文件调用 C 函数。因此,这个问题是不正确的,没有答案,但如果您遇到这个 undefined symbol 问题,还要考虑检查您没有混合使用 C 和 C++。]

我正在使用 uVision 5 开发固件,但是我无法让链接器找到我的函数之一。

main.c:

#include "Test.h"

int main()
{
return three();
}

测试.h:

#ifndef TEST_H
#define TEST_H

int three();

#endif

测试.c

#include "Test.h"

int three()
{
return 3;
}

所有这些文件都位于我的项目的根目录中,我知道它们会被编译,就像我在其中引入语法错误一样,编译器会报告错误。另外查看生成的 map 文件,我发现 Three() 已被删除:

Removing test.o(i.three), (4 bytes).

出于测试目的,我对链接器命令行设置了 --no_remove,映射文件现在包含:

0x0002ba76   0x00000004   Code   RO            1    i.three             test.o

很明显,链接器很清楚我的函数,并且会或不会根据标志删除它。

无论如何,它报告:

.\build\uvision5\test.axf: Error: L6218E: Undefined symbol three() (referred from main.o).
Not enough information to list image symbols.

最佳答案

有缺陷的问题,这实际上是混合 C/C++ 的情况,在这种情况下,如果从 C++ 调用 C 函数而不将其声明为 extern C,则会丢失符号。

关于c - 错误: L6218E: Undefined symbol three(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41993145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com