添加静态库入动态库时,符号查找不到的问题
编译静态库进入动态库时,有时会出现编译通过,调用时却出现symbol查找不到的问题。
这是因为链接静态库时,只会将编译时用到的符号添加进动态库,有些符号是希望动态加载,在编译的时候并未显示调用。
这时需要将静态库全部链接。
1 -Wl,--whole-archive \ 2 -Wl,--start-group \ 3 -lopencv_core \ 4 -Wl,--end-group \ 5 -Wl,--no-whole-archive \
-Wl,option
Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. You can use this syntax to pass an argument to the option. For example, -Wl,-Map,output.map
passes -Map output.map
to the linker. When using the GNU linker, you can also get the same effect with `-Wl,-Map=output.map'.
即表明之后的命令是传递给linker的选项。
--whole-archive 表明将所以object全部链接进来。
--start-group和--end-group用于解决循环依赖问题,因此,组内的库可以多次搜索新的符号,并且您不需要像-llib1 -llib2 -llib1这样的丑陋的构造
-(
archives -)
or --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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2017-08-07 用shell查找某目录下的最大文件(转)
2017-08-07 Linux 后台开发常用命令
2017-08-07 RAID详解[RAID0/RAID1/RAID10/RAID5] (转)
2017-08-07 Gperftools中tcmalloc的简介和使用(转)
2015-08-07 Word Ladder 未完成
2015-08-07 标准C++中的string类的用法总结