简体   繁体   中英

compiling shared library (old standard) with c++11 shared library

I'm trying to compile a shared library (A) that uses another shared library (B).

The A library have to be compiled without adding -std=c++11 option to g++ (because there are tons of code, and some things like std::make_pair will not work with the '11 standard).

For using the B library, the first one just #include "Bh" in one of its files, and then compile with -I/path/inc -L/path/lib -lB .

The library B is formed by a set of functions inside the namespace B , and includes some classes definitions in its own namespace (B::internals). The relation between functions and class is a static pointer in the global scope, initialized with an __attribute__((constructor)) .

The problem is that this class (B::internals::classB) defines some std::mutex private attributes, and, following the include's chain: libA -> libB -> B::internals -> std::mutex , makes that when compiling libA without -std=c++11 standard compilation fails.

However, libA never uses B::internals , so it should not be a problem mixing both libraries. Also, if the c++11 features are private attributes, why are they not hidden to libA?. Is there some pattern for hide B::internals to libA?

There is a C++ idiom for hiding implementations details called Pimpl .

Also, the library compiled with different C++ options must not expose any std containers in its interface because their layout is different in different C++ versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM