Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2022-05-12 12:30:11


On 5/12/22 13:52, Kenneth Porter via Boost wrote:
> Can one mix compilation units or libraries built with different versions
> of C++?

This question seems to be unrelated to Boost, but in general you should
avoid mixing different C++ versions in one application. There was an ABI
change between C++03 and C++11 at least in libstdc++. I'm not 100% sure
there weren't any incompatibilities between other C++ versions, and I'm
not following other implementations. There definitely were additions and
changes in standard library APIs between C++ versions, though those are
less likely to break ABI compatibility.

> If I build my DLL with C++20, can a customer use it with their
> C++11 app?

It depends. If you're using C++20 features in public headers, those
won't compile when included in a C++11 app. Also, your library will be
linked to C++20 symbols in the standard library, which means the app
will still require a C++20 standard library to link with.

> How are compiler and library vendors dealing with this?
> Do/will they supply multiple binaries for each C++ version? (I'm already
> building for each architecture plus release/debug. Adding the compiler
> version explodes the number of binaries to build and test.)

Compiler vendors usually provide a single binary for all C++ versions
(some vendors provide debug/release and static/shared versions). The
binary exports all symbols for all C++ versions supported by it. The way
they achieve this is through namespaces or other ways of different
mangling of symbol names exported by the library. For example, you may
notice libstdc++ exports symbols related to two versions of
std::basic_string - one for C++03, one for C++11 onward.

Library vendors deal with this as they see fit. Most, including Boost,
don't go as far as libstdc++ does and simply use whatever symbols needed
according to the C++ version they are compiled for. This means you'll
have different binaries depending on the C++ version you build for.
Whether those will be ABI-compatible or not, again, depends on the
particular library in question. Maintaining ABI compatibility is a
non-trivial task, not everyone is willing to pursue it.

The best advice I can give in this regard is try to stick with one C++
version for the whole project. Possibly, the default one used by your
compiler. If you need to mix different C++ versions, you have to
explicitly ensure this combination is supported by the libraries.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk