When migrating to C ++ 11, is it necessary to recompile all dependency libraries that use STL in the interface?

I am trying to switch a large project to using C ++ 11. I came across a lot of linker errors, which are apparently caused by an inconsistent namespace on STL classes between a library compiled with C ++ 11 and compiled with C ++ 03 .

As an example, let's say library B is a dependency of A. B has the following template class as part of its interface.

template <class Type> class VectorParameter { public: VectorParameter(); virtual ~VectorParameter(); ... } 

Library A creates an instance of the template using VectorParameter<std::pair<float, float>> .

When I recompiled A with C ++ 11 without recompiling B, I ran into a linker error that complains that

LFE::VectorParameter<std::__1::pair<float, float>>::~VectorParameter() is undefined symbol.

I think the problem here is that library A uses std::__1::pair and B still uses std::pair . Following these considerations, I assume that I will need to recompile all dependency libraries that reference STL types in their interfaces.

If this is the case, then transferring a large project to C ++ 11 will require simultaneous switching of all involved groups, which is not very practical for a complex project. What would be the best practice to solve this problem?

+6
source share
2 answers

You do not specify your platform or compiler / libraries.

There are some interesting notes here (albeit a bit dated) about ABI compatibility for GNU libStdc++ - there is some isolation from ABI compatibility due to reality. Most likely, if you use std::pair , this is all or nothing here.

libc++ (which is the standard clang library) takes a different approach and intentionally inserts an extra namespace (I think is called __1 ) to all exported characters, which means that you can link both libStdc++ and libc++ in the same executable file. By letting you not pass STL objects across the boundaries between old and new libraries, you can very well get this to work.

+3
source

The library header files almost certainly have changed, so you must recompile everything to stay in accordance with the Rule of One Definition .

+8
source

Source: https://habr.com/ru/post/972094/


All Articles