Using a C++17 library against a C++11 application
Asked Answered
P

3

6

Is it possible to consume a library built using C++17 against a C++11 application if all the public facing headers and APIs belonging to the C++17 library that the C++11 application consumes follows C++11 syntax. The internal implementation of the C++17 library does have C++17 specific features.

Does it matter if it's a statically linked vs dynamically linked?

Plasmodium answered 24/7, 2020 at 18:11 Comment(4)
It depends on your toolchain.Bowe
"possible" - yesMaledict
Not necessarily. There is really no ABI standardization in C++. Depends on the toolchain.Passable
Generally, yes.Maisey
S
4

Is it possible to consume a library built using C++17 against a C++11 application if all the public facing headers and APIs belonging to the C++17 library that the C++11 application consumes follows C++11 syntax.

In general, that is a recipe for disaster. In a subset of cases it might work if you are lucky (for instance, if you do not share standard library objects that changed ABI, if you do not trigger any ABI difference in your usage of your API, etc.).

What you want to do instead is compile all your code using the exact same compiler, including compiler version and compiler flags. Even then, you should read your compiler's documentation for further possible issues regarding static/dynamic linking of dependencies and system dependencies.

The internal implementation of the C++17 library does have C++17 specific features.

That is not a problem on its own (in fact, many C++ libraries give C interfaces), but you need to respect whatever linking restrictions/issues your compiler/platform documents.

Does it matter if it's a statically linked vs dynamically linked?

Same. For most platforms, it should not change anything with respect the question of mixing C++11 and C++17, but you still have to take care of the usual issues.

Spode answered 24/7, 2020 at 18:22 Comment(0)
R
3

C++ does not guarantee ABI stability/compatibility. So you always have to compile and link all parts of your application with the exact same compiler and usually with the same compiler options. Some compilers sometimes give binary compatibility guarantees, but don't count on it. Changing language standard versions between objects is often fine though, but in some cases there are ABI (or API) breaks between language versions.

The C++ language gives no guarantees unless you compile everything the same way with the same tools. Basically; compile everything from scratch every time with the same tools and same settings or no guarantees (this includes your code, the code of the standard library as well as the code of any third party libraries you may be using).

Romeo answered 24/7, 2020 at 18:21 Comment(2)
You sound like you are reading out of Titus Winters playbook. That's a compliment! :-)Gnarl
@Gnarl I've heard the name. Don't know anything about the guy. I guess I should look him up.Romeo
T
2

The language doesn't specify.

In general, as soon as you change your compiler version or the version of any libs (exposed or passed between) the guarantee flies out the window. Are you in a position of rebuilding both sides with the same compiler (same version) and same system libs ? If so, you're good. If not, check very carefully the documentation of the compiler and system libs (and don't hold your breath)

Tin answered 24/7, 2020 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.