【问题标题】:Why is clang++ linking to gcc?为什么clang ++链接到gcc?
【发布时间】:2016-10-10 23:35:27
【问题描述】:

我有一个简单的“Hello, world”风格的程序,我正在 FreeBSD 上用 clang++ 编译它:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
    cout << "Oh, hello" << endl;
    return EXIT_SUCCESS;
}

我用 clang++ 及其 libc++ 编译的:

$ clang++ -stdlib=libc++ -v ohhello.cpp 
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang++" -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name ohhello.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/3.8.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /usr/home/mike/projects/ohhello -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/ohhello-050a75.o -x c++ ohhello.cpp
clang -cc1 version 3.8.0 based upon LLVM 3.8.0 default target x86_64-unknown-freebsd11.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/v1
 /usr/bin/../lib/clang/3.8.0/include
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/ohhello-050a75.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

在链接器步骤中,我多次看到“-lgcc”和“-lgcc_s”。如果使用 libc++(不是 libstdc++),为什么 clang++ 会尝试链接 gcc?

谢谢

【问题讨论】:

    标签: c++ gcc freebsd clang++


    【解决方案1】:

    libgcc 不是 gcc。它很小,non compiler-specific C library。它由 gcc 提供,但并不特定于编译器。

    【讨论】:

    • 感谢您的解释。看起来 LLVM 有 compiler-rt 而不是 libgcc,但默认情况下仍在使用 libgcc?
    猜你喜欢
    • 2019-06-21
    • 2013-11-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    相关资源
    最近更新 更多