背景:Debian Jessie gcc
上的默认4.9.2
版本{strong> 不 支持CXX_STANDARD 14
。
[dk@jessie /home/dk/qib]$ /usr/bin/gcc --version
gcc (Debian 4.9.2-10+deb8u1) 4.9.2
我的CMakeLists.txt指定了CXX_STANDARD 14
和CXX_STANDARD_REQUIRED ON
。
因此,我从源代码构建了8.2.0
并将其安装在/usr/local/bin/
的位置:
[dk@jessie /home/dk/qib]$ /usr/local/bin/gcc --version
gcc (GCC) 8.2.0
并指向cmake
指向支持该标准的较新的编译器:
[dk@jessie /home/dk/qib/build]$ cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ -DBUILD_x64=ON ..
问题:然后,已编译的二进制文件指向旧的libstdc++.so.6
,并且出现此错误:
[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)
一种解决方案:
使用cmake
将编译器/链接器指向较新版本的一种方法是(请注意,我们的二进制文件现在链接至较新的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)
问题:是否存在更好的,可移植的,可分发的方式来自动进行构建,假设(理想情况下)无法触摸原始的CMakeLists.txt
(在上游)或使用LD_LIBRARY_PATH
(not advisable anyway)?
我的草稿build.sh
脚本,作为对包管理器(例如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