1

I have a question related to the setting of Multi-threaded Debug DLL (/MDd) and Multi-threaded Debug (/MTd). The difference between them is obvious: one is using dynamic library and the other is using static library. When I compile my program using /MDd, everything goes on very well. However, when I change the setting to /MTd and run the program, Visual Studio will trigger a breakpoint in the program with a pop-up message box. The message is as follows:

Windows has triggered a breakpoint in application.exe.

This may be due to a corruption of the heap, which indicates a bug in application.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while application.exe has focus.

The output window may have more diagnostic information.

I was wondering in this case what I can do next. Thanks!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
feelfree
  • 11,175
  • 20
  • 96
  • 167

2 Answers2

2

It's possible that some other libraries you've included in your application are compiled against the DLL run-time library. If so, then when you try to link your executable against the static run-time library, you end up with two copies: one static and one dynamic. Depending on memory allocation patterns, this can cause one instance of the library to have incomplete information about the heap. Since the debug versions of the library try to detect heap corruption, you see the error. (Note that with the release versions, you might still have an error, you just won't get a notification.)

It's generally necessary to go all-or-nothing when deciding to link against the static or the dynamic run-time library. And, if you're including DLLs other than the standard OS ones, you almost certainly want the dynamic run-time so that everything in the process is using the same instance.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
1

After checking the codes very carefully, I found another situation that can also trigger the same problem, and that is, the memory is located in one dll, but it is released in another dll. For more information on this topic, I refer to Memory allocation and deallocation across dll boundaries

Community
  • 1
  • 1
feelfree
  • 11,175
  • 20
  • 96
  • 167