STe*_*yaK 49 c gcc compiler-errors compiler-warnings
在什么情况下,GCC 在尝试调用伪造函数时不会抛出"未定义的引用"链接错误消息?
例如,GCC编译和链接此C代码的情况:
void function()
{
made_up_function_name();
return;
}
Run Code Online (Sandbox Code Playgroud)
...即使代码中made_up_function_name
没有任何地方(不是标题,源文件,声明或任何第三方库).
GCC是否可以在某些条件下接受和编译这种代码,而无需触及实际代码?如果是这样,哪个?
谢谢.
编辑:之前没有任何声明或提及made_up_function_name
.这意味着grep -R
整个文件系统中的一个只显示完整的单行代码.
Dmi*_*kov 84
是的,可以使用--unresolved-symbols
链接器选项来避免报告未定义的引用.
g++ mm.cpp -Wl,--unresolved-symbols=ignore-in-object-files
Run Code Online (Sandbox Code Playgroud)
从 man ld
--unresolved符号=方法
确定如何处理未解析的符号.方法有四种可能的值:
Run Code Online (Sandbox Code Playgroud)ignore-all Do not report any unresolved symbols. report-all Report all unresolved symbols. This is the default. ignore-in-object-files Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files. ignore-in-shared-libs Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries. This can be useful when creating a dynamic binary and it is known that all the shared libraries that it should be referencing are included on the linker's command line.
共享库的行为也可以通过 - [no-] allow-shlib-undefined选项控制.
通常,链接器将为每个报告的未解析符号生成错误消息,但选项--warn-unresolved-symbols可以将此更改为警告.