zoukankan      html  css  js  c++  java
  • gcc编译选项的循环重复查找依赖库等命令

    link时,若liba.a依赖libb.a,若这样写 -lb -la,则链接通不过,gcc有个选项:-Xlinker ,可以让gcc在链接时反复查找依赖库,用法 :

    gcc -shared -o libxx.so xx.o  -L.  -Xlinker  "-("  -lb -la "-)" -Xlinker

    这样,包含在 -Xlinker  "-("      和       "-)" -Xlinker  之间的库之间的依赖关系就不用自己操心了,linker自己知道前向回去搜索一次。

    (注:   --start-group  与 --end-group   与上面的 -Xlinker功能差不多,不过不推荐)

    linker还有一个选项,主要用在当用静态库生成动态库时,将静态库完整打包到动态库里,不过会使动态库占用空间变大,不推荐,示例:

    gcc -shared -o libxx.so xx.o -L. -Wl,--whole-archive some_static_lib.a yy.o -Wl,--no-whole-archive

    -Wl,--whole-archive 和 -Wl,--no-whole-archive 必须成对出现,不然出现 redefine错误,因为隐性的 -lc -ld -lm -lz 等都被多次完整打包,容易出现 redefine错误。



    对于多个静态库,最好不要用ar将它们打包到一个静态库,链接后的so库有可能会存在 undefined symbol 的符号,在运行时候才会触发错误(链接时不会出错)。

    多个静态库还是推荐单独使用他们为好,即: -la -lb -lcc -ldd。 

    不推荐将 liba.a libb.a libcc.a libdd.a 用ar打包成一个库来使用,不然运行有可能出错的。

  • 相关阅读:
    my first android test
    VVVVVVVVVV
    my first android test
    my first android test
    my first android test
    ini文件
    ZZZZ
    Standard Exception Classes in Python 1.5
    Python Module of the Week Python Module of the Week
    my first android test
  • 原文地址:https://www.cnblogs.com/lidabo/p/13808323.html
Copyright © 2011-2022 走看看