是的,使用--unresolved-symbols
链接器选项可以避免报告未定义的引用.
g++ mm.cpp -Wl,--unresolved-symbols=ignore-in-object-files
从man ld
--unresolved-symbols=method
确定如何处理未解析的符号.一共有四个
方法的可能值:
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.
共享库本身的行为也可以是
通常,链接器将 for each
报告的未解析符号,但选项--warn-unsolved-symbols可以
将此更改为警告.