隐藏符号 __dso_handle 问题

这几天要给项目做移植,重写了下Makfile。项目原是使用autoconf配置的,但在新环境下对autoconf的支持不好。

Makefile编写基本按autoconf生成的Makefile来的,编译选项等等,但是在使用动态库时报了下面的错误:

/usr/bin/ld: client: hidden symbol `__dso_handle' in /usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output

网上搜到的结果都是是gcc/g++的binUtils的问题,编译动态库需要使用gcc/g++ -shared而不能直接使用ld,而我的Makefile就是这么做的,结果还是出现了这个问题.

逐步取得编译连接选项,发现取得-nostdlib后即可成功编译,看来是这个的问题.

看了下gcc的文档,使用该选项是是不是用系统启动文件(不知道怎么翻译)的,这就说明除非你在代码里自己处理crt启动问题,否则不要用这个选项:

-nostdlib
Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify are passed to the linker, and options specifying linkage of the system libraries, such as -static-libgcc or -shared-libgcc, are ignored.
原文地址:https://www.cnblogs.com/D3Hunter/p/3346805.html