Background: Default gcc
version on Debian Jessie 4.9.2
does not support CXX_STANDARD 14
.
[dk@jessie /home/dk/qib]$ /usr/bin/gcc --version
gcc (Debian 4.9.2-10+deb8u1) 4.9.2
My CMakeLists.txt specifies CXX_STANDARD 14
and CXX_STANDARD_REQUIRED ON
.
So I built 8.2.0
from source and installed in /usr/local/bin/
location:
[dk@jessie /home/dk/qib]$ /usr/local/bin/gcc --version
gcc (GCC) 8.2.0
and pointed cmake
to the newer compiler supporting that standard:
[dk@jessie /home/dk/qib/build]$ cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ -DBUILD_x64=ON ..
Problem: The compiled binary then points to old libstdc++.so.6
and I get this error:
[dk@jessie /home/dk/qib/build]$ ldd ../bin/qib.0.0.1.so
../bin/qib.0.0.1.so: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ../bin/qib.0.0.1.so)
../bin/qib.0.0.1.so: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ../bin/qib.0.0.1.so)
linux-vdso.so.1 (0x00007ffd43ee9000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff532750000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff53244f000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff532239000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff531e8e000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff532cdc000)
One solution:
One way of pointing the compiler/linker to the newer version using cmake
is this (note that our binary now links to the newer libstdc++.so.6.so
):
[dk@jessie /home/dk/qib/build]$ cmake -E env CXXFLAGS="-Wl,-rpath,/usr/local/lib64/" cmake -DBUILD_x64=ON -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ ..
...
[dk@jessie /home/dk/qib]$ ldd bin/qib.0.0.1.so
linux-vdso.so.1 (0x00007ffd3533b000)
libstdc++.so.6 => /usr/local/lib64/libstdc++.so.6 (0x00007f54340e0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5433ddf000)
libgcc_s.so.1 => /usr/local/lib64/libgcc_s.so.1 (0x00007f5433bc8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f543381d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f54346e4000)
Question: Are there better, portable, distributable ways to automate the build, assuming (ideally) one cannot touch the original CMakeLists.txt
(it's upstream) or use LD_LIBRARY_PATH
(not advisable anyway)?
My draft build.sh
script, as input to package manager such as conda
:
[dk@jessie/home/dk/qib]$ cat build.sh #!/bin/bash
mkdir build && cd build
cmake -E env CXXFLAGS="-Wl,-rpath,/usr/local/lib64/" cmake -DBUILD_x64=ON -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ ..
make