Building application in debug with release CRT wit

2019-08-02 08:50发布

问题:

I am building an application with dependency on boost. My application output is libraries that end up being used by another client application. I recently discovered I was building my application in debug mode using /MDd for code generation (debug CRT libraries) and that the client application was built against release CRT even in debug mode. Hence this can cause some memory heap corruption errors. To confirm, this I tested everything in release mode and there it all works fine.

To address this issue, I built my application in debug mode against CRT release libraries... but now my application (in standalone tests) fails at run time. My understanding is this is due to the boost dependency and that boost debug is built perhaps against debug CRT libraries? I looked in the boost docs but couldn't find exactly what I wanted... which is how to rebuild boost (in debug mode) against release CRT? Appreciate any help/ideas/examples. Thanks for your time!

回答1:

In addition to @AlKepp's answer, I'd like to suggest to have a look at Dependency Walker (http://dependencywalker.com/). It's a free tool that shows you which libraries your library or application depends on. Usually you should make sure that either only the Release or the Debug version of the Microsoft C/C++ Runtime DLLs show up (eg MSVCP90.DLL vs MSVCP90D.DLL).

If your app loads more libraries at runtime (e.g. plugins), run the application from Dependency Walker using Profile->Start Profiling. It will then show you all libraries that are actually loaded or tried to be loaded during execution.

This is a great help to resolve any dependency issues, and it helped me a lot especially in this case of accidentally mixing release and debug builds.



回答2:

I had similar issues in the past. I solved it by using only release builds with debugging features turned on. You can either change the default Release configuration to generate all the required debug information and omit optimizations or some of them, or you can create a clone of the default Release configuration to let you have both the original (i.e. real Release) and you debug-enabled release configuration.



标签: c++ boost crt