- 主题:为什么c++链接依赖库一定要出现在被依赖的后面,出于什么考虑的
搞得这么膈应
--
FROM 223.160.129.*
正好是Linker的搜索顺序吧
静态库的话,可以分组的,同一个组里的静态库是可以无视顺序的,这样能解决互相依赖时的问题。
官方文档有说明
https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_mono/ld.html
https://sourceware.org/binutils/docs/ld/Options.html
-larchive
--library=archive
Add archive file archive to the list of files to link. This option may be used any number of times. ld will search its path-list for occurrences of libarchive.a for every archive specified. On systems which support shared libraries, ld may also search for libraries with extensions other than .a. Specifically, on ELF and SunOS systems, ld will search a directory for a library with an extension of .so before searching for one with an extension of .a. By convention, a .so extension indicates a shared library. 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 which was 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. You may list the same archive multiple times on the command line. This type of archive searching is standard for Unix linkers. However, if you are using ld on AIX, note that it is different from the behaviour of the AIX linker.
--
修改:z16166 FROM 114.240.244.*
FROM 114.240.244.*
gcc链接静态库,遇到过找不到符号定义的情况,把依赖的静态库库名字列两遍就可以了。
【 在 z16166 的大作中提到: 】
: 正好是Linker的搜索顺序吧
: 静态库的话,可以分组的,同一个组里的静态库是可以无视顺序的,这样能解决互相依赖时的问题。
: 官方文档有说明
: ...................
--
FROM 223.104.39.*
多列几遍没问题,也是那个文档里推荐的搞法
用-Wl,--start-group、-Wl,--end-group对静态库分组也是没问题的
【 在 toutouqi 的大作中提到: 】
: gcc链接静态库,遇到过找不到符号定义的情况,把依赖的静态库库名字列两遍就可以了。
--
修改:z16166 FROM 114.240.244.*
FROM 114.240.244.*
有意思
还能强制多搜索几遍
【 在 z16166 的大作中提到: 】
: 正好是Linker的搜索顺序吧
: 静态库的话,可以分组的,同一个组里的静态库是可以无视顺序的,这样能解决互相依赖时的问题。
: 官方文档有说明
: ...................
--
FROM 47.91.30.*
历史遗留问题
早期实现gnu linker的时候因为cpu内存的限制
就搞了个这么简单的符号查找机制
这和一般程序员的mental model不一致
然而他们就这样忍了几十年
据说llvm lld可以选择gnu linker的行为还是在提供的所有库中查找的行为
【 在 stub 的大作中提到: 】
: 搞得这么膈应
--
FROM 107.204.171.*