简体   繁体   中英

Using Boost with C++14 compiler

When I am compiling my code with C++11 support (using the -std=c++11 flag) and use non-header-only Boost libraries, then I need to have Boost compiled with -std=c++11 . This is because Boost has some interface differences in header files when C++11 is enabled, and some function signatures are different for the different C++ standards.

My question is whether the same is true with C++14 (using g++ 4.9, with the `-std=c++1y flag), or is it safe to use Boost compiled with C++11 for a program compiled with C++14?

This is a very broad question that is difficult to answer definitively, because

  • Boost is a federation of libraries, many of which are over decade old
  • there are quite a lot of backward compatibilities that could in principle happen, some detected by the compiler, and some only by unit tests
  • many Boost libraries are actually C++98 implementations of C++11/14 features (both library and compiler functionality), so that you would not need to use this in a C++11/14 project.
  • Boost itself is very much debating at which pace the library should be updated to C++11/14, whether V2 versions of libraries should be written that fully take advantage of C++11/14, and even whether new C++11/14 libraries should offer backward C++98 compatibility

You might want to closely read your compiler errors (if any) and compare them to the list of breaking changes listed below. Furthermore, I would recommend following the Boost test harness for finding suspect compiler/library combinations that apply to your system.

Some relevant Q&A's here:

  1. What breaking changes are introduced in C++11?
  2. What changes introduced in C++14 can potentially break a program written in C++11?
  3. Relevant boost features vs C++11
  4. How well does boost use c++11?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM