rstr1112
rstr1112

Reputation: 428

Using a C++17 library against a C++11 application

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?

Upvotes: 8

Views: 1405

Answers (3)

Acorn
Acorn

Reputation: 26136

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.

Upvotes: 5

Jesper Juhl
Jesper Juhl

Reputation: 31472

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).

Upvotes: 4

Jeffrey
Jeffrey

Reputation: 11430

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)

Upvotes: 2

Related Questions