• 添加静态库入动态库时,符号查找不到的问题


    编译静态库进入动态库时,有时会出现编译通过,调用时却出现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.

     
  • 相关阅读:
    mysql启动失败一例
    Windows 10 执行pip list报错 UnicodeDecodeError: 'gbk' codec can't decode
    GPT转MBR
    python_查找模块的方法
    python_函数中使用*和**
    Python_单元测试工具nose
    状态迁移法
    场景分析法
    可爱的Python_课后习题_CDay0 时刻准备着!发布
    可爱的Python_课后习题_CDay−2 完成核心功能
  • 原文地址:https://www.cnblogs.com/zl1991/p/9437192.html
Copyright © 2020-2023  润新知