[cfe-dev] getting clang to find non-default libstdc++

Marc Glisse marc.glisse at inria.fr
Sat Apr 28 01:37:21 PDT 2012


On Fri, 27 Apr 2012, Nathan Ridge wrote:

> Hello,
>
> I am trying to use clang for the first time, on Ubuntu 10.04.
>
> The default compiler on Ubuntu 10.04 is GCC 4.4, but I've built
> GCC 4.7 from source and use it to compile C++11 programs.
>
> Clang finds GCC 4.4's libstdc++ no problem, but I need it to
> use GCC 4.7's libstdc++ because my program uses standard
> library features that have been added between GCC 4.4 and 4.7.
> How do I direct clang to find the 4.7 libstdc++?
>
> I saw the following instructions on the "Get Started" page:
>
> "If Clang cannot find your system libstdc++ headers, please
> follow these instructions:
>  - 'gcc -v -x c++ /dev/null -fsyntax-only' to get the
>    path.
>  - Look for the comment "FIXME: temporary hack:
>    hard-coded paths" in clang/lib/Frontend/InitHeaderSearch.cpp
>    and change the lines below to include that path"
>
> Is that the only way? Having to recompile the compiler to get
> it to find a different standard library seems a bit excessive...
> shouldn't one be able to switch standard libraries without
> recompiling the compiler?

Yes, of course. Finding the standard library is no magic, you can simply 
add some -isystem, -L, and possibly -Wl,-rpath arguments to clang++ when 
using it. Use the -v option to see what clang is using by default, so you 
can just add the same with s/4.4/4.7/g. If clang puts one of its own 
directories first (before the gcc ones), be sure to specify it again 
yourself so it still ends up first. You can even try some flags like 
-nostdinc++ to clean up a bit (again, check with -v that the list makes 
sense).

-- 
Marc Glisse



More information about the cfe-dev mailing list