2

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
Cinder Biscuits
  • 4,880
  • 31
  • 51
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75

1 Answers1

3

My suggestion is to work as you are crosscompiling your project: just set up a toolchain file and prepare for build (Linux example):

mkdir -p build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/toolchain/file ..

Whenever you need to change the compiler or just some of the compile options you just need to change the toolchain file, without touching the CMakeLists.txt

You can find the reference here, but there are almost no information. A good tutorial is here.

ErniBrown
  • 1,283
  • 12
  • 25
  • 1
    According to http://stackoverflow.com/a/31092052, `-H` and `-B` flags are undocumented because they shouldn't be used. The answer links to https://cmake.org/pipermail/cmake-developers/2016-June/028843.html which says `"These are undocumented because they are internal options that are not meant for public use"` and suggests `mkdir -p "$build" && pushd "$build" && cmake "$src" && popd` instead – Daniel Krizian Jan 16 '19 at 14:19