Mixing debug and release libraries in Visual Studio

buffer overrun

Mixing debug and release code is bad practice.

Different compiled versions can depend on different fundamental parts of the C++ runtime library, such as how memory is allocated, structures for things like iterators might be different, extra code could be generated to perform operations. In particular, the std containers and iterators are different and incompatible and do not let this work.

Sometimes one get the following error

A buffer overrun has occurred in Program_64.exe which has corrupted the program’s internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic ‘How to debug Buffer Overrun Issues’.

So are we stuck?

But what if you have inherited the release library and do not have the source code. You are stuck for development and if the compiler is not letting you to use these libraries in your debug development code.

But we are not entirely stuck, here’s a workaround that worked for me.

// the offending libraries
#include "quad.h"
#include "uqtktools.h"

#include "mytypedef.h"

using namespace std;

The work around

#ifdef _DEBUG
#undef _DEBUG
// the offending libraries
#include "quad.h"
#include "uqtktools.h"

#define _DEBUG

#include "mytypedef.h"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s