0
votes

I can not test my application so decided to find out more. This is the situation: I have a third party static library that I like to use it in my MFC application. I created a MFC dialog based application, it built successfully both in debug and release. I was more interested in MFC Single document, therefore I created a MFC SD app and linked the header and library as before then started building.

With the MFC SD app, these is what I got:

  1. In debug mode with RT option set to "Multi-threaded Debug DLL (/MDd)", got some LNK2005 error stuff.

  2. In debug mode with RT option set to "Multi-threaded DLL (/MD)", got couple of warnings only:

    LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs;use /NODEFAULTLIB:library

    LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

  3. In release mode with RT option set to Multi-threaded DLL (/MD)" got no errors or warnings.

what these indicate?. Are these as expected. Is the app expected to work under the option 2 and 3?. I like to be able to run my app in debug mode first to debug it then turn it to release mode.

Why MFC SD vs. dialog based behave so differently in this regard?

1

1 Answers

0
votes

The problem is that you use code that is compiled with different CRT options. I am sure it is caused by you static lib.

If you get warnings like under 1.+2. it shows that one part of you code links to one CRT code platform and other part of your code need other CRT code.

The effect is, that you have code for malloc, free new, delete in several versions in you your exe. So one part of your code might allocate memory with the debug core and another part of your code frees it with the release version... or vice versa.

Or you code sets a locale, and this locale isn't use in another code part that uses a different CRT...

In fact if you don't use the same CRT flags for a static library there is no guaranty that your code will work and strange things will not happen.

As long as you have a static library all settings for

  • Compiler Version
  • Debug / Release
  • CRT Usage (as DLL or static)
  • MFC Usage (static or DLL)

must match!