可以GCC不要抱怨未定义的参考? [英] Can GCC not complain about undefined references?

查看:209
本文介绍了可以GCC不要抱怨未定义的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么样的情况有可能是GCC为不可以扔当试图打电话编造的功能是什么?一个未定义的引用链接错误信息

Under what situation is it possible for GCC to not throw an "undefined reference" link error message when trying to call made-up functions?

例如,在此C code由GCC编译和链接的情况:

For example, a situation in which this C code is compiled and linked by GCC:

void function()
{
    made_up_function_name();
    return;
}

...即使 made_up_function_name 不是present的随时随地在code(不是头,源文件,声明,也没有任何第三方库)。

...even though made_up_function_name is not present anywhere in the code (not headers, source files, declarations, nor any third party library).

能否那种code来接受和GCC在一定条件下编译,不接触实际的code?如果是这样,这?

Can that kind of code be accepted and compiled by GCC under certain conditions, without touching the actual code? If so, which?

感谢。

编辑:没有previous声明或提及对 made_up_function_name 是present其他地方。这意味着一个的grep -R 整个文件系统将显示,准确的code的一行。

no previous declarations or mentions to made_up_function_name are present anywhere else. Meaning that a grep -R of the whole filesystem will only show that exact single line of code.

推荐答案

是的,这是有可能避免的报告未定义的引用 - 使用 - 未解决的,符号链接器选项。

Yes, it is possible to avoid reporting undefined references - using --unresolved-symbols linker option.

g++ mm.cpp -Wl,--unresolved-symbols=ignore-in-object-files

男人LD

- 未解决-符号=法

确定如何处理未解决的符号。有四个
  对于方法可能值:

Determine how to handle unresolved symbols. There are four possible values for 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.


  
  

自己共享库的行为,也可
  由受控 - [无糖]允许-SHLIB-不确定的选项

The behaviour for shared libraries on their own can also be controlled by the --[no-]allow-shlib-undefined option.

一般情况下,链接器将生成的每个错误消息
  报道未解决的象征,而是选择--warn悬而未决,符号可以
  更改为一个警告。

Normally the linker will generate an error message for each reported unresolved symbol but the option --warn-unresolved-symbols can change this to a warning.

这篇关于可以GCC不要抱怨未定义的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆