[cfe-dev] Building clang from source and header/library search paths

Edward Diener eldlistmailingz at tropicsoft.com
Wed Dec 18 16:19:27 PST 2013


On 12/17/2013 06:35 PM, Hans Wennborg wrote:
> Hi Edward,
> 
> On Tue, Dec 17, 2013 at 3:24 PM, Edward Diener
> <eldlistmailingz at tropicsoft.com> wrote:
>> When clang is built on a Linux distro from the latest source as
>> described by http://clang.llvm.org/get_started.html how are the default
>> header and library search paths determined ?
> 
> I don't know exactly how it works, but the code that tries to find the
> headers and libraries is in lib/Driver/ToolChains.cpp. It's entirely
> possible that it gets things wrong on some systems.
> 
>> On a particular Linux distro, using gcc 4.7.2, there is an older clang
>> distribution package installed ( 3.2 ) and it finds the header and
>> libraries in the gcc distribution without any problems. Yet if I build
>> the latest clang as described in the URL above successfully, that latest
>> version does not find the header and libraries in the gcc distribution
>> at all. So I am trying to understand why this is happening.
>>
>> In the URL above I do see the explanation:
>>
>> "If you intend to use Clang's C++ support, you may need to tell it how
>> to find your C++ standard library headers. In general, Clang will detect
>> the best version of libstdc++ headers available and use them - it will
>> look both for system installations of libstdc++ as well as installations
>> adjacent to Clang itself. If your configuration fits neither of these
>> scenarios, you can use the --with-gcc-toolchain configure option to tell
>> Clang where the gcc containing the desired libstdc++ is installed."
>>
>> but I do not understand either how to determine what clang is detecting
>> or how to tell it to, via the "-with-gcc-toolchain" configuration
>> option, where to find the correct headers and libraries.
> 
> One way to debug this is to run clang on a file with the -v option. It
> should first spit out some lines such as:
> 
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.6
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.6.3
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
> 
> And later on, it should print out where it's actually trying to search
> for headers:
> 
> ignoring nonexistent directory
> "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/x86_64-linux-gnu/c++/4.6"
> ignoring nonexistent directory "/include"
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6
> 
> etc.

This is on Mageia 3.0.

Running "clang++ -v -x c++ /dev/null" for the default clang package,
which is version 3.2, gives:

> clang version 3.2 (tags/RELEASE_32/final)
> Target: x86_64-mageia-linux-gnu
> Thread model: posix
>  "/usr/bin/clang" -cc1 -triple x86_64-mageia-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name null -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.23.51.0.8.20121218 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.2 -fmodule-cache-path /tmp/clang-module-cache -internal-isystem /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../include/c++/4.7.2 -internal-isystem /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../include/c++/4.7.2/x86_64-mageia-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../include/c++/4.7.2/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.2/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/mgeldiener/dev/clang/build/Debug!
 +Asserts/b
in -ferror-limit 19 -fmessage-length 139 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/null-K7wDgp.o -x c++ /dev/null
> clang -cc1 version 3.2 based upon LLVM 3.2 default target x86_64-mageia-linux-gnu
> ignoring nonexistent directory "/include"
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../include/c++/4.7.2
>  /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../include/c++/4.7.2/x86_64-mageia-linux-gnu
>  /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../include/c++/4.7.2/backward
>  /usr/local/include
>  /usr/bin/../lib/clang/3.2/include
>  /usr/include
> End of search list.
>  "/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/crtbegin.o -L/usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2 -L/usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../.. -L/lib -L/usr/lib /tmp/null-K7wDgp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/crtend.o /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../lib64/crtn.o
> /usr/lib/gcc/x86_64-mageia-linux-gnu/4.7.2/../../../../lib64/crt1.o: In function `_start':
> /home/iurt/rpmbuild/BUILD/glibc-2.17/csu/../sysdeps/x86_64/start.S:119: undefined reference to `main'
> clang: error: linker command failed with exit code 1 (use -v to see invocation)

Now running "./clang++ -v -x c++ /dev/null" on the latest built version
of clang from source, which is version 3.5, gives:

> clang version 3.5 (trunk 197534)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> Selected GCC installation: 
>  "/home/mgeldiener/dev/clang/build/Debug+Asserts/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name null -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.23.51.0.8.20121218 -v -resource-dir /home/mgeldiener/dev/clang/build/Debug+Asserts/bin/../lib/clang/3.5 -internal-isystem /usr/local/include -internal-isystem /home/mgeldiener/dev/clang/build/Debug+Asserts/bin/../lib/clang/3.5/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/mgeldiener/dev/clang/build/Debug+Asserts/bin -ferror-limit 19 -fmessage-length 139 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /tmp/null-53bdd1.o -x c++ /dev/null                                                             
> clang -cc1 version 3.5 based upon LLVM 3.5svn default target x86_64-unknown-linux-gnu                                                      
> ignoring nonexistent directory "/include"                                                                                                  
> #include "..." search starts here:                                                                                                         
> #include <...> search starts here:                                                                                                         
>  /usr/local/include                                                                                                                        
>  /home/mgeldiener/dev/clang/build/Debug+Asserts/bin/../lib/clang/3.5/include
>  /usr/include
> End of search list.
>  "/..//bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /lib/../lib64/crt1.o /lib/../lib64/crti.o crtbegin.o -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/null-53bdd1.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc crtend.o /lib/../lib64/crtn.o
> /..//bin/ld: cannot find crtbegin.o: No such file or directory
> /..//bin/ld: cannot find -lstdc++
> /..//bin/ld: cannot find -lgcc
> clang: error: linker command failed with exit code 1 (use -v to see invocation)

Clearly the latest version is not finding whatever the package version
is finding. I am looking to correct this when building the latest version.





More information about the cfe-dev mailing list