Clang ++ - gcc-toolchain and gcc 4.9.3 binding problems

(Ubuntu 16.04.1)

By default 16.04.1 clang selects the gcc toolchain for 5.4. Unfortunately, I have a library that requires pre-5.0 ABI and I do not have access to the source, and the developer has not released a new version. I tried to use the -gcc-toolchain option, but I can't get it to work. (ctrbegin.o and crtend.o do not get the correct prefix by reference.)

$ clang++-3.8 -v -print-search-dirs clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5.4.0 Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6.0.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.4.0 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.0.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0 Candidate multilib: .;@m64 Selected multilib: .;@m64 programs: =/usr/bin:/usr/lib/llvm-3.8/bin:/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../x86_64-linux-gnu/bin libraries: =/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu: /lib/x86_64-linux-gnu: /lib/../lib64: /usr/lib/x86_64-linux-gnu: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../..: /usr/lib/llvm-3.8/bin/../lib: /lib: /usr/lib 

When I try to specify -gcc-toolchain, clang seems to accept and then completely ignore the value. (The same thing happens with clang ++ - 3.5 on 04.16.1.)

Is this the correct syntax? Please note that library directories are missing at the output.

 $ clang++-3.8 -v --gcc-toolchain=/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3 -print-search-dirs clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin programs: =/usr/bin:/usr/lib/llvm-3.8/bin:/..//bin libraries: =/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/llvm-3.8/bin/../lib:/lib:/usr/lib 

I tried MANY variations of this theme. (4.9, deleting the relative path, etc.) I tried the -system parameter and the -cxx-isystem parameter. (Both are offered as solutions to similar problems.)

What am I missing? (I hope this is easy, but the dizziness is fine!)

+4
source share
3 answers

It seems that you are --gcc-toolchain wrong path to the --gcc-toolchain option. It expects the path to the GCC installation prefix, which is /usr in the case of GCC installed with the package manager. However, I don’t think it’s possible to choose which toolchain to use if you have several versions of GCC installed on your system and all have the same prefix. It seems that clang just takes the latest version in the $PREFIX/lib/gcc/x86_64-linux-gnu . Therefore, I would recommend that you create the tool binding you need and pass the installation prefix --gcc-toolchain .

0
source

Unfortunately, I have a library that requires pre-5.0 ABI and I do not have access to the source

you do not need to switch the gcc-toolchain to change the ABI, as new versions of gcc support dual-abi support .

To switch the ABI by overriding the preprocessor macro:

 clang++ -D_GLIBCXX_USE_CXX11_ABI=0 

So, I would recommend that you create the tool binding you need and pass the installation prefix to the -gcc-toolchain option.

If this is available, you can trick clang to use the selected tool chain by copying your / usr folder via symbolic links, excluding versions of gcc that you don't need.

0
source

As Gaetano wrote in a related ticket, you need to create a separate directory that can be passed to clang as --gcc-toolchain . Here is my slightly refined code. No bin and include links.

 # The libstdc++ version you want to use libstdcxx_version="4.9" # Avoid calling arch twice arch="$(arch)" # The new toolchain root in the current directory toolchain_root="$(pwd)/toolchain" # The gcc library directory to be created toolchain_gcc="$toolchain_root/lib/gcc/$arch-linux-gnu" # Create that directory mkdir -p "$toolchain_gcc" # Find the longest matching libstdc++ version. # Needed for clang-3.8 and older - they need 4.9.x rather than 4.9. libstdcxx_dir=$(ls -d /usr/lib/gcc/$arch-linux-gnu/${libstdcxx_version}* \ | tail -1) # Link the libstdc++ library directory to the new location ln -sfn "$libstdcxx_dir" "$toolchain_gcc/" # Now you can add "--gcc-toolchain=$toolchain_root" to the clang flags 
0
source

Source: https://habr.com/ru/post/1014601/


All Articles