• 三种标准库链接方式


    Linux 应用程序因为 Linux 版本的众多与各自独立性,在工程制作与使用中必须熟练掌握如下两点才能有效地工作和理想地运行。
    1.Linux 下标准库链接的三种方式(全静态 , 半静态 (libgcc,libstdc++), 全动态)及其各自利弊。
    2.Linux 下如何巧妙构建 achrive(*.a),并且如何设置链接选项来解决 gcc 比较特别的链接库的顺序问题。
    全静态:
    1.-static -pthread -lrt -ldl
    2.不会发生应用程序在 不同 Linux 版本下的标准库不兼容问题。
    3.生成的文件比较大,应用程序功能受限(不能调用动态库等)
    全动态
    1.-pthread -lrt -ldl
    2.生成文件是三者中最小的
    3.比较容易发生应用程序在不同 Linux 版本下标准库依赖不兼容问题。
    半静态 (libgcc,libstdc++)
    1.-static-libgcc -L. -pthread -lrt -ldl
    2.灵活度大,能够针对不同的标准库采取不同的链接策略,从而避免不兼容问题发生。
    3.结合了全静态与全动态两种链接方式的优点。
    4.比较难识别哪些库容易发生不兼容问题,目前只有依靠经验积累。
    5.某些功能会因选择的标准库版本而丧失。

    Linux 静态库链接顺序问题及解决方法:
    正如 GCC 手册中提到的那样:
    It makes a difference where in the command you write this option; the linker
    searches and processes libraries and object files in the order they are specified.
    Thus, ‘ foo.o -lz bar.o ’ searches library ‘ z ’ after file ‘ foo.o ’ but before
    ‘ bar.o ’ . If ‘ bar.o ’ refers to functions in ‘ z ’ , those functions may not be loaded.
    为了解决这种库链接顺序问题,我们需要增加一些链接选项 :
    $(CXX) $(LINKFLAGS) $(OBJS) -Xlinker “-(” $(LIBS) -Xlinker “-)” -o $@
    通过将所有需要被链接的静态库放入 -Xlinker “-(” 与 -Xlinker “-)” 之间,可以是 g++ 链接过程中, 自动循环链接所有静态库,从而解决了原本的链接顺序问题。
    涉及链接选项:-Xlinker
    -Xlinker option
    Pass option as an option to the linker. You can use this to supply system-specific
    linker options which GCC does not know how to recognize.

    http://www.kxtry.com/archives/566

  • 相关阅读:
    any、some、all for sql
    Date CONVERT() 函数
    Config Database
    移动master 数据库
    使用 OpenRowSet 和 OpenDataSource 访问 Excel 972007
    动态管理视图和函数
    SQL Server 2005 Merge Replication Step by Step Procedure
    系统试图(返回表所有记录数及所有的 identity 列)
    js if without curly brackets bug All In One
    Web3 All In One
  • 原文地址:https://www.cnblogs.com/findumars/p/5661850.html
Copyright © 2020-2023  润新知