简体   繁体   English

构建C ++ dll以进行发布和调试

[英]Build C++ dll for Release and Debug

So I'm getting into c++ and I recently built a logger class ie print any type to the screen and/or to a log file. 所以我开始使用C ++,最近我建立了一个logger类,即在屏幕和/或日志文件上打印任何类型。 I built it as a dll and the output files are 我将其构建为dll,输出文件为

console.h
console.lib
console.dll

I then imported these files as additional includes to another project and it works, only in debug mode (in which it was built) I wish for it to work regardless of build config. 然后,我将这些文件作为其他包含项导入到另一个项目中,并且它只能在调试模式下(该文件是在其中构建的)工作,而无论构建配置如何,我希望它都能工作。 How can I accomplish this. 我该怎么做。 An example, I recently used the GLFW library and can build in both how was it compiled for this to work. 一个例子,我最近使用了GLFW库,并且可以内置这两种库的编译方式以使其正常工作。

If I correctly understood you're trying to link same version of your lib/dll with both debug and release configs of your app. 如果我正确理解,您正在尝试将相同版本的lib / dll与应用程序的调试和发布配置链接在一起。

In general case you need two versions of your lib/dll files, debug and release, and link with the one that matches your application configuration, so for debug config of you app link with debug config of your lib/dll, and release with release. 通常,您需要两个版本的lib / dll文件(调试和发行版),并链接到与您的应用程序配置匹配的版本,因此对于您的应用程序的调试配置,请链接到您的lib / dll的调试配置,并与发行版一起发布。

The most possible problem of using mixed configs (like debug dll with release exe) is allocating memory in one domain and releasing it in another. 使用混合配置(例如带有发布exe的调试dll)的最可能问题是在一个域中分配内存,然后在另一个域中释放内存。

EDIT: 编辑:

To elaborate, the problem can be allocating memory in your DLL and releasing it in your EXE, or vise versa. 详细地说,问题可能出在DLL中分配内存并在EXE中释放它,反之亦然。 This doesn't work, at least with VS C-Runtime. 这至少在VS C-Runtime中不起作用。 For more details, see: https://stackoverflow.com/a/45806858/453271 有关更多详细信息,请参阅: https : //stackoverflow.com/a/45806858/453271

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM