Reputation: 1101
I am required to use a shared library A and its API which was compiled using C++11. It uses C++11 features like std::mutex
and std::shared_ptr
in its API. I have no control over library A.
However, I am also being required to compile my code using C++03 which uses library A's API.
I am pretty sure that this cannot be done because I get compiler errors stating that the uses of std::mutex
, std::shared_ptr
, and others in the API are not found. (My understand is, if library A didn't use C++11 specific types then I should be able to do this.)
But I just want to make sure that there isn't something I am not understanding that I need to do in order to compile my code against the C++11 library A.
So the question is, can I compile my code using C++03 against a shared library and its API that uses C++11?
Upvotes: 2
Views: 316
Reputation: 249183
An API which exposes at its edges any C++11-specific features won't be usable from C++03. One way you could work around this would be to build a C++11 wrapper for the library which converts all C++11-specific inputs and outputs to C++03-compatible types. For example if the original C++11 library returns a std::shared_ptr
from its API, the wrapper library could return a boost::shared_ptr
or a raw pointer instead. The "Pimpl" idiom might be helpful when implementing the wrapper, e.g. if you need to make wrappers for smart pointers but can't allow your application code to see std::shared_ptr
at all.
But the question has to be asked: why not just enable C++11 for your existing code?
Upvotes: 3