Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Clang come with standard library headers?

I downloaded Clang 3.6.2 from this website and am trying to set it up with Code::Blocks under Windows. Unfortunately, it fails to compile a simple "hello world" program on the grounds that it doesn't know where iostream is.

Looking through the install folder, it does not appear to include a standard library with it. Why? And how do I get it?

like image 544
Therhang Avatar asked Jul 22 '15 04:07

Therhang


People also ask

Where does Clang look for headers?

Clang searches for them in a directory relative to the location of the clang binary. If you moved the clang binary, you need to move the builtin headers, too.

Does Clang support STD format?

Clang can use either libstdc++ or libc++ as standard library implementation. The linked page says that std::format is implemented (with the limitations mentioned when you hover over the version number) in libc++ but not in libstdc++.

Is Clang slower than GCC?

Sometimes a program is a lot faster when compiled with GCC, sometimes it's a lot faster with clang. Usually it's marginally faster with GCC. Clang attempts to unroll loops really, really aggressively. Even at -O2 : Clang's loop unrolling attempts at -O2 are more aggressive than GCC's loop unrolling attempts at -O3 .

Which is better GCC or Clang?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.


1 Answers

The standard library is NOT part of the compiler itself. It is part of the runtime environment on a particular platform. Sure, some organisations put together a "kit" with all the necessary parts to build an application - there may even be someone that packages a Clang compiler with a suitable runtime.

In general, you should be able to download the Windows SDK and get the relevant header files there - and if you use clang-cl, it should be largely compatible with the MSVC compiler [or provide clang or clang++ with the correct -fms-compatibility or whatever it is called].

Or as suggested in the other answer, use libcxx, but it's not 100% complete for Windows.

like image 133
Mats Petersson Avatar answered Oct 14 '22 10:10

Mats Petersson