Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost build fails C++11 feature checks when using (custom) GCC 4.x or 5.x

Tags:

c++

gcc

c++11

boost

b2

I need to build Boost 1.62 and 1.63 on a Fedora 24 machine, but using GCC 4.9.3 or GCC 5.4.0 (depending on the version CUDA, which is the reason why I need an older compiler). But if I set the custom GCC version as described in this answer and run

/b2 --toolset=gcc-5.4.0 stage

To my chagrin, I now see:

    - 32-bit                   : no
    - 64-bit                   : yes
    - arm                      : no
    - mips1                    : no
    - power                    : no
    - sparc                    : no
    - x86                      : yes
    - symlinks supported       : yes
    - C++11 mutex              : no
    - lockfree boost::atomic_flag : yes
    - Boost.Config Feature Check: cxx11_auto_declarations : no
    - Boost.Config Feature Check: cxx11_constexpr : no
    - Boost.Config Feature Check: cxx11_defaulted_functions : no
    - Boost.Config Feature Check: cxx11_final : yes
    - Boost.Config Feature Check: cxx11_hdr_tuple : no
    - Boost.Config Feature Check: cxx11_lambdas : no
    - Boost.Config Feature Check: cxx11_noexcept : no
    - Boost.Config Feature Check: cxx11_nullptr : no
    - Boost.Config Feature Check: cxx11_rvalue_references : no
    - Boost.Config Feature Check: cxx11_template_aliases : no
    - Boost.Config Feature Check: cxx11_thread_local : no
    - Boost.Config Feature Check: cxx11_variadic_templates : yes

i.e. a lot of C++11 features are supposedly missing, while they should not be. This does not occur when building it with the distribution's GCC version (6.2.1).

Why is this happening and what should I do to make the Boost build recognize my GCC 5.4.0 (or 4.9.3)'s capabilities?

like image 263
einpoklum Avatar asked Oct 03 '16 07:10

einpoklum


1 Answers

The following solution was tested with Boost 1.62.0 + GCC 4.x, Boost 1.62.0 + GCC 5.x and Boost 1.65.1 + GCC 5.x. YMMV with other Boost versions but I see no reason why it shouldn't work.

Let's assume for the sake of this example that:

  • You want to build Boost with GCC 5.4
  • The g++ 5.4 binary is at /some/where/g++-5.4
  • You've downloaded the Boost sources and unpacked them into /path/to/sources/of/boost-1.62.0/
  • (Perhaps) you want to install Boost to /dest/path
  • You have N cores (so you want to parallelize the build N-ways)

Now:

  1. (Optional: Make sure you have the libraries Boost likes to have, e.g.: zlib, bzip2, lzma, zstd, iconv, icu)
  2. cd /path/to/sources/of/boost-1.62.0/
  3. Booststrap the build system by running ./bootstrap.sh
  4. echo "using gcc : 5.4 : /the/path/to/g++-5.4 : <cxxflags>-std=c++11 ;" > ./tools/build/src/user-config.jam
  5. ./b2 --toolset=gcc-5.4 -j N (N being the number of cores on your system)
  6. ./b2 install --prefix=/dest/path

Notes:

  • The order of actions 2 and 3 doesn't matter.
  • Rejoice! This doesn't happen with GCC 6.x or later versions.
  • You can replace c++11 with c++1y if you want GCC 5.4.0's (non-finalized) C++14 support. If you're using a different GCC version, remember that before a standard is finalized you don't actually get its switch available. Thus C++11 used to mean --std=c++1x and C++17 was --std=c++1z and the switches change as GCC versions get released after standard finalization.
like image 95
einpoklum Avatar answered Sep 27 '22 16:09

einpoklum