There are "sayings" on the web that LLVM (Clang) is built with GCC compatibility in mind and that it uses many of GCC's tools to compile code. However that does not make sense; isn't Clang a more advanced replacement for GCC? So straight to the point, does Clang use GCC at all? Are they related?
Asked
Active
Viewed 1,432 times
3
-
There is even MSVC compatibility: [https://clang.llvm.org/docs/MSVCCompatibility.html](https://clang.llvm.org/docs/MSVCCompatibility.html) – drescherjm Aug 18 '20 at 20:50
-
Clang is not a "more advanced replacement for GCC". Clang does not use GCC at all. Clang was definitely inspired by GCC, and has many (but not all) of the same flags. I believe the impetus for the creation of Clang was the GCC licensing, which Apple found disagreeable for them. – Eljay Aug 18 '20 at 20:51
-
1It's unclear why you think Clang more advanced than GCC. It's *younger* as a project, but that could be taken as an argument for the opposite position. Both projects continue to be actively developed, so there is no basis there, either, to assert that one is more advanced than the other. – John Bollinger Aug 18 '20 at 20:54
-
@JohnBollinger I've just repeatedly noticed that Clang optimizes code much better in terms of performance, and is built on top of LLVM which has made a name for itself in terms of optimization, so I assumed from that and from what I would read online that Clang might be more advanced than GCC. I also did not know that GCC is being actively developed so maybe I'm wrong. – xdraxulisx Aug 18 '20 at 21:00
-
@xdraxulisx Any source for your performance claims? – P.P Aug 18 '20 at 21:07
-
Clang can be built by GCC, MSVC, etc. Any good compiler can be boostrapped by itself or another compiler. – Michael Dorgan Aug 18 '20 at 21:10
-
Also, because GCC came first, why not support all its flags? It also tries to support MSVC flags are well, because that makes things easier yes? Easier to use, more people will use it... – Michael Dorgan Aug 18 '20 at 21:13
-
@P.P [Apple](https://opensource.apple.com/source/clang/clang-23/clang/tools/clang/www/comparison.html) and [StackOverflow](https://stackoverflow.com/questions/3187414/clang-vs-gcc-which-produces-faster-binaries) for example. – xdraxulisx Aug 18 '20 at 21:54
-
What you have probably heard about: clang does indeed use gcc for some things. System-dependent paths etc. If a particular platform requires all apps to link with foo, clang often learns that by asking gcc. They also are compatible in the sense that they can link with the same libraries, etc. – arnt Aug 18 '20 at 21:58
-
@arnt That's a very concise answer. Thank you! – xdraxulisx Aug 18 '20 at 22:19
-
@xdraxulisx That's (SO post)nearly 10 years old. And I don't see the Apple link claiming clang's perrofmance is superior. A more recent comparison suggests [gcc's runtime performance is better](https://medium.com/@alitech_2017/gcc-vs-clang-llvm-an-in-depth-comparison-of-c-c-compilers-899ede2be378). – P.P Aug 19 '20 at 05:54
-
@P.P Well both are great, this is just a minor thing as runtime performance is much more important than build performance. – xdraxulisx Aug 19 '20 at 15:14
1 Answers
11
Depending on how it is configured, clang can use gcc components, e.g: to retain compatibility. Clang, just like gcc, is a compiler, and a compiler frontend. Strictly speaking, a C++ compiler does not link code, the linker does it. Clang can use either gnu ld, gold, lld or others. Those are all linkers, some part of the gcc toolchain. A compiler also needs a standard library, clang can use libstdc++, libc++ or others. libstdc++ is part of the gcc toolchain, and a popular option to remain compatible with other system wide components.

erenon
- 18,838
- 2
- 61
- 93
-
But why would Clang use GCC if it can use its own tools? And practically speaking I think it does (I'm no expert though); for example, I've tried implementing concurrency many times in my programs which wouldn't compile using GCC on the basis that libraries such as
do not exist, then would compile fine using Clang. This maybe my mistake and not really something caused by GCC, but it means that Clang uses a different stdlib than GCC. As for the linker for example, doesn't Clang use its own like in Xcode for example? – xdraxulisx Aug 18 '20 at 20:55 -
I'm in no way trying to question your response, I'm new here, so I'm just trying to make sense of the messy world of C++. – xdraxulisx Aug 18 '20 at 20:55
-
BinUtils - there are newer, not quite as universally used tools from Clang, but not completely backwards compatible. This is one place where GCC tools are still used. – Michael Dorgan Aug 18 '20 at 21:12
-
GCC is officially supported as compiler for llvm. Some optimisation in gcc are better than in llvm, but it is mostly some naive mistakes https://discourse.llvm.org/t/require-gcc-7-5-as-gcc-7-3-cannot-build-llvm-16-x-or-main/72310 – Валерий Заподовников Jul 28 '23 at 05:27