Ask Your Question

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


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

1 answer

Sort by ยป oldest newest most voted

answered 2019-06-10 04:58:35 -0500

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.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-06-10 03:09:54 -0500

Seen: 54 times

Last updated: Jun 10 '19