Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is clang++ linking to gcc?

I have a simple "Hello, world" style program that I'm compiling with clang++ on FreeBSD:

#include <cstdlib>
#include <iostream>

using namespace std;

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

Which I compile with clang++ and its 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

In the linker step I see "-lgcc" and "-lgcc_s" multiple times. Why is clang++ trying to link against gcc if it's using libc++ (not libstdc++)?

Thanks

like image 631
SonOfFlyingPig Avatar asked Oct 10 '16 23:10

SonOfFlyingPig


People also ask

Why does Clang call GCC?

It's because you're linking with a C runtime (from Glibc) built with GCC, and the linker is merging the two together.

Does clang depend on GCC?

Clang depends on libgcc and crt object files. They can be built and installed independently, of course, but there is no canonical way of doing so.

Does clang require GCC?

Clang is a completely separate compiler (written entirely from scratch, using LLVM). You don't need GCC to use Clang, as can be shown in the case of FreeBSD (they completely replaced GCC with Clang/LLVM and don't install GCC in the base anymore for licensing reasons).

Is clang replacing GCC?

Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection (GCC), supporting most of its compilation flags and unofficial language extensions.


1 Answers

libgcc is not gcc. It is a small, non compiler-specific C library. It is provided by gcc, but it is not specific to the compiler.

like image 54
Sam Varshavchik Avatar answered Sep 28 '22 11:09

Sam Varshavchik