5

Suppose my C++ is standard-compliant and I don’t rely on third-party libraries, what are the usual pitfalls encountered when replacing “g++” to “clang++” in the makefile? Like incompatible compiler options, different requirement of option order, some other limitations, etc.

Leedehai
  • 3,660
  • 3
  • 21
  • 44

1 Answers1

4

TL;DR: Clang is highly compatible to GCC - just give it a go.

In most cases, Clang could be used as a GCC drop in replacement (clang and clang++ are "GCC compatible drivers"). Clang was designed with GCC compatiblity in mind, and most options available in GCC should also be supported by Clang.

In my experience, of using GCC and Clang interchangeably on several projects, I don't recall any case where Clang failed to compile where GCC succeeded.

However, depending on size and complexity of your project, migration may not be completely smooth. There are several factors that may be impactful, including compiler bugs and different code generation, which may impact application performance and in rare cases even application functionality. Switching compilers is a big change, so once you're able to build successfully, it's a good idea to run all available tests and benchmarks.

Here are just a few examples from SO for GCC and Clang possible incompatibilities. Chances are, you won't encounter such issues.

RE: option order - both GCC and Clang accept compiler flags in any order.

valiano
  • 16,433
  • 7
  • 64
  • 79