You must link the ‘Release’ version of the MFC/CRT libraries when compiling ObjectARX applications

<?xml encoding=”UTF-8″>by Fenton Webb

Issue

My application uses the dynamic version of MFC and the DLL run-time library. When I link for debug, a warning about MSVCRT conflicting with other libraries occurs. When I use the /verbose:lib switch, I notice that during the link that it links the debug versions of MFC and the run-time library. The ARX  Developer’s Guide says not to use the debug versions. What settings do I use so that it will use the release versions of MFC for a debug link?

Solution

All you have to do is undefine the _DEBUG switch during #include of MFC header
files.

A good place to do this is in the STDAFX.H file generated by AppWizard.

NOTE:  The MFC/CRT headers actually test to see if _DEBUG is defined, if it is then debug versions of the libs are linked otherwise the release versions are linked. Obviously, a DLL running inside of a release product such as AutoCAD needs to be linked with the release versions of the MFC and CRT libraries to prevent a mixing of the heaps and possible crashing of your debug compiled application.

At the top of the file put in the following lines of preprocessor code:

<pre><br>#if defined(_DEBUG) && !defined(DEBUG_AUTOCAD)<br>   #define _DEBUG_WAS_DEFINED<br>   #undef _DEBUG<br>   #define NDEBUG<br>#endif<br></pre>

At the bottom of STDAFX.H add the following lines of preprocessor code:

<pre><br>//----- at the end of STDAFX.H<br>//----- Turn on the _DEBUG symbol if it was defined, before including<br>//----- non-MFC header files.<br>#ifdef _DEBUG_WAS_DEFINED<br>  #undef NDEBUG<br>  #define _DEBUG<br>  #undef _DEBUG_WAS_DEFINED<br>#endif<br></pre>

This will allow you to debug your code and still use the release MFC libraries.

An extra point to note is that if you create your ObjectARX application using our ObjectARX Wizard AddIn for Visual Studio, all this will be handled for you automatically.

Also, you can just remove the _DEBUG define from your project settings but remember that this may remove some of your debugging code.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading