4

I'm looking specifically for a clang answer to this question. If I compile one object with -std=c++11 and another with -std=c++17 can they be safely linked?

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174

1 Answers1

2

The answer posted here by Jonathan Wakely is correct for Clang as well.

Easy answer: if you're compiling both of the objects yourself, the -std option you choose won't affect the final outcome.

Most of a given C++ ABI is decided by the standard library. The rest is assorted runtime support such as exceptions, compiler builtins (which may actually dispatch to the standard library), and things like that. libstdc++ ABI compatibility is an explicit goal of for Clang, so you're ok here.

If you're using the same compiler version, the -std option will change which symbols get exposed to code when you compile. However, libstdc++'s ABI for stable features is forwards compatible, so you'd also be OK here too.

Harder answer: Your comments suggest you have the source, but if you only have object files and are just doing the final link, there's a good chance it will work unless the version of Clang used to build the std=c++11 object is very old. The g++ and libstdc++ authors went out of their way to version symbols, so the chances of you having something that links, but then fails in a hard to diagnose way is basically zero. (This is referred to in the second to last paragraph in Jonathan's answer).

Again, since Clang aims to keep compatibility with libstdc++'s ABI, you should be fine. There are other details, but the vast majority are addressed in Jonathan's answer, and he's in a better position to explain it than I am.

Community
  • 1
  • 1
jared_schmitz
  • 583
  • 2
  • 10