【问题标题】:GCC flags during linking链接期间的 GCC 标志
【发布时间】:2014-08-09 10:00:50
【问题描述】:

在过程的链接部分是否有任何情况下可能与 -ansi、-Wall 和 -pedantic 等标志相关?

-O 优化标志呢?它们是仅在编译步骤期间相关还是在链接期间也相关?

谢谢!

【问题讨论】:

标签: c gcc compilation linker


【解决方案1】:

实际上,没有 - 但在理论上,-ansi 是一种方言选项,因此可以想象它可能会影响链接。当分别使用 C++11 或 C++03 时,我已经看到使用 libc++ 或 libstdc++ 的旧版本 clang 的类似行为。我发现将这些标志放在CC 变量中更容易:CC = gcc -std=c99CC = gcc -std=c90 (ansi)。

出于习惯,我只是用$CXX$CC 调用C++(或C)。并且默认传递给配置脚本。

我不知道这是 C 的问题,只要 ABI 和调用约定没有改变。另一方面,C++ 需要更改 C++ 运行时以支持新的语言特性。无论哪种情况,都是编译器使用相关库调用链接器。

【讨论】:

    【解决方案2】:

    gcc 中有链接时优化:

       -flto[=n]
           This option runs the standard link-time optimizer.  When invoked
           with source code, it generates GIMPLE (one of GCC's internal
           representations) and writes it to special ELF sections in the
           object file.  When the object files are linked together, all the
           function bodies are read from these ELF sections and instantiated
           as if they had been part of the same translation unit.
    
           To use the link-time optimizer, -flto needs to be specified at
           compile time and during the final link. 
    

    【讨论】:

      猜你喜欢
      • 2015-07-10
      • 2020-09-07
      • 1970-01-01
      • 2013-04-09
      • 2018-05-21
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多