locked
Unwanted link to msvcrt.lib in debug builds RRS feed

  • Question

  • Hi all!

    (VS2008)

    I have a fairly large project that spans several libraries. For some reason, Debug build links with msvcrt.lib (msvcr90.dll). That gives a horrible crash due to heap mismatch.

    So I am trying to find the cause for the bad link. When I turn on /VERBOSE on the link, I can see that for some CRT function calls in at least one library I use, linker is searching inside msvcrt.lib, and finds what it wants there. I looked around makefiles for these libraries, I checked all other libraries, and I failed to find the reason for that. AFAICanSee, I am consistently using /MD for release, and /MDd for debug builds.

    So I tried /NODEFAULTLIB:msvcrt.lib. That caused the linker to stop looking into msvcrt.lib, and I am back in business.

    So... Does anyone has an idea where I went wrong?

    I am thinking, if msvcrt is needed, link should fail with /NODEFAULTLIB:msvcrt.lib. Conversely, if msvcrt.lib is not needed, linker should not look for it.. By the way, I am carrying this code since VS98, and I don't remember ever changing build settings, not intentionally anyhow.

    TIA,

    Goran.

    Thursday, January 20, 2011 10:19 AM

Answers

  • Hi Goran,

     

    The Preprocessor could be a problem, this page shows the information about compiler CRT library option and their corresponding preprocessors, http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.90).aspx.

     

    In addition, is that possible that the whole solution in release mode is using /MD, but one of a CPP file is using /MDd?

     

    Regards,

    Yi Feng Li  


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Yi Feng Li Monday, January 31, 2011 4:00 AM
    Friday, January 21, 2011 4:39 AM
  • Hi Goran,

     

    Based on my understanding, it should link successful and it will not be an issue of unresolved symbols. /NODEFAULTLIB:msvcrt.lib option tells the linker to remove msvcrt.lib from the list of libraries it searches when resolving external references. For the CRT symbols, they will be found either in release mode CRT or in debug mode CRT. Suppose a project is set to /MD only, after setting /NODEFAULTLIB:msvcrt.lib, it will cause unresolved symbols errors, Similar for /MDd. However, if the projects loads both release and debug library, once /NODEFAULTLIB:msvcrt.lib is set, whole project is linked into debug mode CRT only which resolve the this issue.

     

    Hope the explanation helps.

     

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Yi Feng Li Monday, January 31, 2011 4:00 AM
    Monday, January 24, 2011 8:00 AM

All replies

  • As far as I know linking with msvcrt.lib is not only a matter of linker-options.
    There are also compiler-options and preprocessor directives, who control, which or if at all to link with msvcrt.ib (libcpmt.lib).
    So probably a include file has changed.
    But I can be wrong, for this is not my special area.
    http://msdn.microsoft.com/en-us/library/abx4dbyh(v=VS.80).aspx
    Thursday, January 20, 2011 12:12 PM
  • Hi, thanks for taking time... Good idea to mention preprocessor. I indeed spent most of my time chasing /MD in debug build configurations, and explicit "#pragma comment (lib:"")" pragmas. I'll see if there are any rogue preprocessor directives somewhere.

    Thursday, January 20, 2011 1:13 PM
  • Hi Goran,

     

    The Preprocessor could be a problem, this page shows the information about compiler CRT library option and their corresponding preprocessors, http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=VS.90).aspx.

     

    In addition, is that possible that the whole solution in release mode is using /MD, but one of a CPP file is using /MDd?

     

    Regards,

    Yi Feng Li  


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Yi Feng Li Monday, January 31, 2011 4:00 AM
    Friday, January 21, 2011 4:39 AM
  • Right, thanks, I will check that.

    Question, though: I am having trouble with debug, not release build, so my problem could rather be that the debug configuration of some project uses /MDd, but some file is using /MD. But shouldn't link then fail if I use /NODEFAULTLIB:msvcrt.lib? Cause, it doesn't. Mere use of /NODEFAULTLIB:msvcrt.lib fixes all, which I find strange. any thoughts?

    Friday, January 21, 2011 8:05 AM
  • Hi Goran,

     

    Based on my understanding, it should link successful and it will not be an issue of unresolved symbols. /NODEFAULTLIB:msvcrt.lib option tells the linker to remove msvcrt.lib from the list of libraries it searches when resolving external references. For the CRT symbols, they will be found either in release mode CRT or in debug mode CRT. Suppose a project is set to /MD only, after setting /NODEFAULTLIB:msvcrt.lib, it will cause unresolved symbols errors, Similar for /MDd. However, if the projects loads both release and debug library, once /NODEFAULTLIB:msvcrt.lib is set, whole project is linked into debug mode CRT only which resolve the this issue.

     

    Hope the explanation helps.

     

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Yi Feng Li Monday, January 31, 2011 4:00 AM
    Monday, January 24, 2011 8:00 AM
  • Hi Goran,,

     

    Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know. I will be more than happy to be of assistance.

     

    Regards,

    Yi

     


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 26, 2011 5:13 AM