ld时静态库的顺序
来源:互联网 发布:美工钢笔书法作品欣赏 编辑:程序博客网 时间:2024/04/27 15:31
android4.4中chromium的so在编译时将各部分都单独编译成单独的静态库,ld时将所有的静态库链接为so文件
ld时出现如下错误
external/chromium_org/components/autofill/core/browser/form_structure.cc:524: error: undefined reference to XmlElement::~XmlElement()'很奇怪的错误
原因就是链接多个静态库,且这些静态库之间有依赖时,静态库在command line的顺序不对
举例:假设liba.a 依赖于libb.b,目标test需要liba和libb,那么生成test的命令应该为
gcc -o test -la -lb 而不是gcc -o test -lb -la
也可以使用ld的 --start-group xxx --end-group来将所有相互依赖的静态库放到xxx位置,只有就能保证search多次了
man ld
The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol whichwas undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again. See the -( option for a way to force the linker to search archives multiple times.
-( archives -)--start-group archives --end-group The archives should be a list of archive files. They may be either explicit file names, or -l options. The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved. Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives.
链接错误:
有时候链接时,明明已经将所有的依赖库都加进去了,还是莫名其妙的报ld error,原因可能就是
1. 上面说的依赖库是静态库时,有先后顺序,如果加上--start-group和--end-group就可以了。
2. 还有可能是,你编译出来的库和你使用的库的版本不一样,导致接口有可能不用,即你使用的库的头文件和你编译依赖库的头文件不一样。不要想当然的认为一样,最好用用beyondcompare等工具比较一下
参考
http://stackoverflow.com/questions/4191275/libjingles-xmpppump-compilation-problem
0 0
- ld时静态库的顺序
- 如何查看ld(连接器)的搜索顺序及编译时需要打开的库
- 如何查看ld(连接器)的搜索顺序及编译时需要打开的库
- ld-linux.so查找共享库的顺序
- ld-linux.so查找共享库的顺序
- 静态链接时链接库的顺序
- 静态库的链接顺序
- 静态库的链接顺序
- ld链接器的链接顺序
- 使用LD链接时候文件的顺序
- GCC/LD编译链接潜规则 (第二弹) : 为什么总链接失败? --LD对依赖库的输入顺序敏感
- gcc连接静态库的时候的出现错误/usr/bin/ld: cannot find -lc
- 链接静态库的顺序问题
- 交叉编译静态库的链接顺序
- linux下静态库的依赖顺序
- 静态链接库的依赖顺序
- Linux系统下 连接器ld链接顺序的总结
- 静态代码的执行顺序
- 2014北京网络赛1006||hdu5037 思维题
- 使用MFC 发送消息模拟按钮按下事件
- 安全运维之:Linux后门入侵检测工具的使用
- ubuntu下提交代码 git commit -a 将编辑器默认的nano改为vim
- 时尚型男怎样选择一款适合自己的香水
- ld时静态库的顺序
- NSLayoutConstraint
- vimrc配置文件
- UVa - 11136 Hoax or what (水题 最大最小堆 set)
- Android之Weight属性源码解析
- LeetCode: Maximal Rectangle
- Md5加密
- CSS3的calc()使用
- java国际化