如何让GCC或LD报告未定义的符号,而不是失败? [英] How to make gcc or ld report undefined symbols but not fail?

查看:920
本文介绍了如何让GCC或LD报告未定义的符号,而不是失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您编译使用GCC的共享库,并通过了-z DEFS标志(我认为这只是获取到LD盲目传递),那么你得到的符号没有定义什么是好的报告,和ld失败(无.so文件创建)。在另一方面,如果不指定-z DEFS或明确指定-Z nodefs(默认值),那么一个.so会产生即使符号丢失,但你没有什么符号报告失踪(如有)。

If you compile a shared library with GCC and pass the "-z defs" flag (which I think just gets passed blindly on to ld) then you get a nice report of what symbols are not defined, and ld fails (no .so file is created). On the other hand, if you don't specify "-z defs" or explicitly specify "-z nodefs" (the default), then a .so will be produced even if symbols are missing, but you get no report of what symbols were missing if any.

我想两个!我想创建的。所以,我也想报告任何丢失的符号。我知道要做到这一点迄今唯一的办法就是两次运行它,用-z DEFS,一次一次都没有。这意味着潜在的长连接阶段,虽然两次完成,这将使编译/测试周期更是雪上加霜。

I'd like both! I want the .so to be created, but I'd also like any missing symbols to be reported. The only way I know of to do this so far is to run it twice, once with "-z defs" and once without. This means the potentially long linking stage is done twice though, which will make the compile/test cycle even worse.

如果你想知道我的终极目标 - 编译库时,在本地目标文件未定义的符号表示没有指定依赖性本来应该在我的编译环境,而如果一个符号在失踪您所链接到的该库是不是一个错误(-l标志仅给出直接的相关性,而不是依赖的相关性,在这种体制下)。我需要的,它里面列出,在文件中引用部分的报告,所以我可以看到符号是否是由本地对象或者被链接的库引用。该--allow-SHLIB-不确定的选项几乎修复了这个而是针对静态库链接时它不工作。

In case you're wondering my ultimate goal -- when compiling a library, undefined symbols in a local object file indicates a dependency wasn't specified that should have been in my build environment, whereas if a symbol is missing in a library that you're linking against that's not an error (-l flags are only given for immediate dependencies, not dependencies of dependencies, under this system). I need the report for the part where it lists "referenced in file" so I can see whether the symbol was referenced by a local object or a library being linked. The --allow-shlib-undefined option almost fixes this but it doesn't work when linking against static libraries.

preference到解决方案,同时与GNU和Solaris链接工作。

Preference to solutions that will work with both the GNU and Solaris linkers.

推荐答案

从GNU LD 2.15 NEWS文件:

From the GNU ld 2.15 NEWS file:


  • 改进了连接器的处理未解决的符号。开关
    --unresolved-符号=已经添加时,它告诉链接器
    应报告它们和开关--warn悬而未决-符号已被添加到
    使报告将作为警告消息而不是错误。

这篇关于如何让GCC或LD报告未定义的符号,而不是失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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