C ++链接版本库和我的调试版本 [英] C++ Linking release built library with my debug build

查看:102
本文介绍了C ++链接版本库和我的调试版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已下载第三方库,并以释放模式构建了.lib文件。
将lib添加到我的项目后,如果我在发布模式下运行我的项目,很好。但是如果我在调试模式下运行我的项目,我得到一个错误:

I've downloaded a 3rd party library, and built the .lib file 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:


  • 构建一个DLL,以便获得你自己的C运行库的副本

  • 不跨共享库边界共享CRT资源,例如堆。 C代码的最大的事情是动态分配的内存必须在边界的同一侧释放。对于C ++代码,您可以在DLL中使用 std 命名空间,但不会跨越边界传递这些对象。

  • 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.

这是预先构建的第三方库最有可能完成的。只有当外部接口不共享CRT对象时,您才能对库执行相同的操作。或者,您可以创建单独的发布和调试版本作为静态库。

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.

这篇关于C ++链接版本库和我的调试版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆