开发者

C++ Linking release built library with my debug build

开发者 https://www.devze.com 2023-02-28 15:57 出处:网络
I\'ve downloaded a 3rd party library, and built the .lib 开发者_如何学Cfile in \'release\' mode.

I've downloaded a 3rd party library, and built the .lib 开发者_如何学Cfile in 'release' mode. After adding the lib to my project, if i run my project in release mode, it's fine. But if i run my project in debug mode, i get an error:

_iterator_debug_level value '0' doesn't match value '2;

I could rebuild the library in debug mode, but I don't think I'll need to be debugging the library itself? And I've downloaded prebuilt 3rd party libraries before which only come with a release build (i assume?) that link fine whether my project is in debug or release. I'm wondering how that is done.


If you want to distribute a release library that others can use in either release or debug mode, you need to do two things:

  • Build a DLL, so that you get your own copy of the C runtime library
  • Not share CRT resources, such as the heap, across the library boundary. The biggest thing for C code is that dynamically allocated memory has to be deallocated on the same side of the boundary. For C++ code, you can use the std namespace inside your DLL, but not pass those objects across the boundary.

That's what the pre-built third-party libraries have most likely done. You can do the same thing with your library only if the external interface doesn't share CRT objects. Or you can build separate release and debug versions as static libraries.


Looks like your debug binary and the library you downloaded use incompatible iterator debug modes. Iterator debugging is usually controlled by macros. Depending on macro values the sizes of interators and many other objects can change. You are lucky that your program emitted useful error message instead of simply crushing.

Check the library documentation and make sure that your project uses the same iterator debug mode. You may also try recompiling the library in release mode. If that doesn't help, you would have to recompile the library in debug mode, even if you don't intend to debug the library itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消