Why is it safe to pass cv::String& accross DLL boundary?

asked 2019-06-10 03:22:05 -0500

I've recently learnt that it's highly not recommended to pass any STL object across the shared library boundary, because their ABI is not standardized, and so if the library and the code that uses it are compiled with different compilers, the STL objects could be perceived differently (different byte order etc).

Some functions in OpenCV take const cv::String& as an argument (imread(), imwrite() etc), and here I see that cv::String is just a typedef to std::string.

So why aren't there any problems with using OpenCV as a shared library?

edit retag flag offensive close merge delete

Comments

which opencv version are you talking about ?

please be very careful here, since opencv4 switched back to std::string under the hood

berak gravatar imageberak ( 2019-06-10 04:50:22 -0500 )edit

Yeah, I relied on the docs for v4.1.0. And since cv::String is std::string under the hood, I'm confused how can it be passed safely when OpenCV is linked dynamically.

azymohliad gravatar imageazymohliad ( 2019-06-10 04:58:35 -0500 )edit