Locating standard library when using -cc1

Hi cfe-dev,

I’ve installed llvm/clang 3.1 on my debian testing box and I must say its working pretty well. I decided to be braver and use the completion mode in emacs, which, if I understood things correctly, relies on the clang compiler driver. The problem I have is that when I use the clang compiler driver I it doesn’t seem to be able to locate the standard library:

$ clang -cc1 -fsyntax-only hello.cpp
hello.cpp:1:10: fatal error: ‘iostream’ file not found
#include
^
1 error generated.

But all is well with the GCC driver:

$ clang -fsyntax-only hello.cpp
$

I’ve tried adding -stdlib=libstdc++ but had no luck. How to I convince the clang compiler driver to find the GCC standard library?

Many thanks for your time,

Marco

Hi

I’ve installed llvm/clang 3.1 on my debian testing box and I must say its working pretty well. I decided to be braver and use the completion mode in emacs, which, if I understood things correctly, relies on the clang compiler driver. The problem I have is that when I use the clang compiler driver I it doesn’t seem to be able to locate the standard library:

I ran into this issue myself a bit ago. I solved it by compiling normally (without -cc1) and use the -### argument. This will list the full commands used at compile time, including the arguments loading the standard library locations. I think it was the -internal-isystem and -internal-externc-isystem arguments you want to look out for, but there could be others.

Hope that helps,

Dan

clang -fsyntax-only hello.cpp -###

Then copy the clang -cc1 command this prints.

Sebastian

Daniel,

Many thanks for the prompt reply. This was extremely useful, I managed to get my simple hello world to compile and to provide me with accurate code completion. However, when I try the same trick with real code things don’t go so well. The steps I performed were:

  • run using the GCC driver with your -### argument: clang -fsyntax-only XYZ -###. All good.
  • copy the entire command line returned and run it: all good.
  • add -code-completion-at=XYZ to the command line: not so good.

I basically get lots and lots (and lots) of STL errors such as:

/usr/bin/…/lib/gcc/x86_64-linux-gnu/4.7/…/…/…/…/include/c++/4.7/bits/alloc_traits.h:56:35: error:
in-class initializer for static data member is not a constant expression
static const bool __value = _S_chk<_Alloc, _Tp>(nullptr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~

These error does not appear to be triggered when I’m not using -code-completion-at. They also do not appear with -code-completion-at and my simple hello world, but, admittedly, the real code includes a fair chunk of the standard library as opposed to the hello world which only includes iostream.

Cheers

Marco