Control selected GCC installation / selected libstdc++ version?

Heya,

I just installed GCC6 on my system (which obviously comes with a new libstdc+
+), and this, unfortunately, breaks Clang.

Long story short: In this particular case I can't build LLVM anymore, since
clang errors out:

/usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0/../../../../include/c++/6.0.0/
tuple:1381:14: error: no matching constructor for initialization of
'tuple<llvm::LexicalScope *&&, const llvm::DILocalScope *&&, nullptr_t &&,
bool &&>'
    { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

I'm not interested in solving the error, I'm more concerned about this: Is it
possible to force Clang into using a specific libstdc++ version? Right now it
seems to just choose the highest version available(?)

# clang++-3.6 -E -v
Ubuntu clang version 3.6.2-3ubuntu1 (tags/RELEASE_362/final) (based on LLVM
3.6.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
(snip)
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.3.1
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/6.0.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

^ How can I force clang to use /usr/lib/gcc/x86_64-linux-gnu/5.3.1 instead,
for instance?

Is that even possible? I had a brief look at tools/clang/lib/Driver/
ToolChains.cpp, but couldn't find any knobs I could use from the command-line.

Cheers,
Kevin

Heya,

I just installed GCC6 on my system (which obviously comes with a new
libstdc+ +), and this, unfortunately, breaks Clang.

Long story short: In this particular case I can't build LLVM anymore, since
clang errors out:

/usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0/../../../../include/c++/6.0.0/
tuple:1381:14: error: no matching constructor for initialization of
'tuple<llvm::LexicalScope *&&, const llvm::DILocalScope *&&, nullptr_t &&,
bool &&>'
    { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

I'm not interested in solving the error, I'm more concerned about this: Is
it possible to force Clang into using a specific libstdc++ version? Right
now it seems to just choose the highest version available(?)

# clang++-3.6 -E -v
Ubuntu clang version 3.6.2-3ubuntu1 (tags/RELEASE_362/final) (based on LLVM
3.6.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
(snip)
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.3.1
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/6.0.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

^ How can I force clang to use /usr/lib/gcc/x86_64-linux-gnu/5.3.1 instead,
for instance?

Is that even possible? I had a brief look at tools/clang/lib/Driver/
ToolChains.cpp, but couldn't find any knobs I could use from the
command-line.

Bump.

Any idea? Am I missing something?

Do you a think a patch which introduces an env var setting for specifying the
desired libstdc++ version would be acceptable?

Cheers,
Kevin

Try passing -DGCC_INSTALL_PREFIX to cmake. You can grep the config files to see how it’s used.

hth… don

Heya,

I just installed GCC6 on my system (which obviously comes with a new
libstdc+ +), and this, unfortunately, breaks Clang.

Long story short: In this particular case I can't build LLVM anymore, since
clang errors out:

/usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0/../../../../include/c++/6.0.0/
tuple:1381:14: error: no matching constructor for initialization of
'tuple<llvm::LexicalScope *&&, const llvm::DILocalScope *&&, nullptr_t &&,
bool &&>'
     { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

I'm not interested in solving the error, I'm more concerned about this: Is
it possible to force Clang into using a specific libstdc++ version? Right
now it seems to just choose the highest version available(?)

# clang++-3.6 -E -v
Ubuntu clang version 3.6.2-3ubuntu1 (tags/RELEASE_362/final) (based on LLVM
3.6.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
(snip)
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.3.1
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/6.0.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

^ How can I force clang to use /usr/lib/gcc/x86_64-linux-gnu/5.3.1 instead,
for instance?

Is that even possible? I had a brief look at tools/clang/lib/Driver/
ToolChains.cpp, but couldn't find any knobs I could use from the
command-line.

For this problem, I don't think there is one.

Bump.

Any idea? Am I missing something?

Do you a think a patch which introduces an env var setting for specifying the
desired libstdc++ version would be acceptable?

An env var for that would not be acceptable, but a command line option probably would be.

Jon

You probably need to specify the version of gcc and the path to libstdc++. Something like this:

export CLANG_GCC=

cmake
-DCMAKE_C_COMPILER=${CLANG_GCC}/bin/gcc
-DCMAKE_CXX_COMPILER=${CLANG_GCC}/bin/g++
-DGCC_INSTALL_PREFIX=${CLANG_GCC}
-DCMAKE_CXX_LINK_FLAGS="-L${CLANG_GCC}/lib64 -Wl,-rpath,${CLANG_GCC}/lib64"
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}

I forgot to add: feel free to tag me as a reviewer if you do come up with a patch.

Jon

Depending on how things look on disk, clang’s --gcc-toolchain option might do what you want. If you locally built a gcc (with libstdc++ and everything) in $HOME/gcc5, then --gcc-toolchain=$HOME/gcc5 should tell to use the libstdc++ from there.

You probably need to specify the version of gcc and the path to libstdc++.
Something like this:

export CLANG_GCC=<path to the version of gcc you want to use>
cmake \
    -DCMAKE_C_COMPILER=${CLANG_GCC}/bin/gcc \
    -DCMAKE_CXX_COMPILER=${CLANG_GCC}/bin/g++ \
    -DGCC_INSTALL_PREFIX=${CLANG_GCC} \
    -DCMAKE_CXX_LINK_FLAGS="-L${CLANG_GCC}/lib64
-Wl,-rpath,${CLANG_GCC}/lib64" \
    -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}

That's a compile switch, when building LLVM/Clang, right?

That's not what I'd like to have. I'd like to decide that later, when invoking
Clang (just assume I only got my distro-provided Clang).

I'll check whether adding a command-line options is feasible (won't happen
tomorrow-ish, no time for that) :slight_smile:

Cheers,
Kevin

Not sure I have the full picture yet, but if you already built clang with a previous version of gcc, then upgraded gcc and got a new version of libstdc++ that isn’t compatible with clang, you need to tell the version of clang you have where the find everything.

When building clang, you can use GCC_INSTALL_PREFIX, but if it’s already built, I think you need to set the environment variable CPATH.

hth…
don