warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs...

This is a discussion on warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs... within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm getting this link warning when compiling a VC++ 6.0 project which includes several other libraries. I know one ...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs...

    Hi,
    I'm getting this link warning when compiling a VC++ 6.0 project which includes several other libraries. I know one of the libraries is linking with the wrong lib file, but I have no control over that library, which leads to this problem:
    Code:
    warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
    I've fixed these kinds of link errors in the past by ignoring "libcmtd.lib" and then adding a different one in the list of libs to include... Sometimes the order of the lib include list also matters. So what I'm wondering is, what's the easiest way to deal with this problem (short of ignoring the warning)?

    The Depends program shows me which DLLs a program or DLL needs in order to run, but is there a similar tool that tells me which lib files another lib uses?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    Is this only a problem for the debug build?

    gg

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    No, not that one. In Release it complains about mfc42u.lib & mfcs42u.lib.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    >> is there a similar tool that tells me which lib files another lib uses
    Code:
    dumpbin /directives xyz.lib
    That will tell you what the default libs are for a particular library.

    >> but I have no control over that library
    First I would figure out who has the wrong settings - your project or the lib's project. Do you have debug version of the lib? Does your Debug target link against the multi-threaded-debug-CRT?

    gg

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Codeplug View Post
    >> is there a similar tool that tells me which lib files another lib uses
    Code:
    dumpbin /directives xyz.lib
    That will tell you what the default libs are for a particular library.
    Thanks. I wish they had a GUI version and put it in the Start menu with the other tools so I can find and use it easier... Oh well...

    Quote Originally Posted by Codeplug View Post
    >> but I have no control over that library
    First I would figure out who has the wrong settings - your project or the lib's project. Do you have debug version of the lib? Does your Debug target link against the multi-threaded-debug-CRT?
    Yes. I think the problem is that the other library links with LIBCMTD.lib and mine links with MSVCRTD.lib. I don't know why VC++ forces me link with the /MDd switch instead of the /MTd switch. Another library I'm linking with uses MFC, which is probably the reason, although I still don't understand that reason. I can use the /MT switch in Release mode just fine, but in Debug it won't let me use /MTd.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    If you have a separate debug and release version of the lib, it sounds like the release build used /MT and the debug build used /MDd. So release is dynamic and debug is static.

    There's nothing wrong with going with /MDd for debug mode - since it is just for debug'n. That's the "safest" thing to do. The other thing you can do is use "/NODEFAULTLIB" to turn off all default lib specifications - but then you have to specify all the libs that you need manually.

    Mixing CRT types can be dangerous, so don't take the warning lightly.

    http://support.microsoft.com/kb/140584

    gg

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    If the debug version of the other library I'm using would have been linked with /MDd, I think my problem wouldn't exist.

    How would you deal with this situation, where your program is linking with 2 other libraries (a.lib & b.lib). a.lib uses libcmtd.lib and b.lib uses MFC and msvcrtd.lib?

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    Yeah, sorry - get'n my switch's and libs mixed up

    Since the only inconsistency is with the CRT, you can ingnore all the CRT libs except the one you want to use. So looking at the table below, pick the row your EXE/DLL should be using for a given target, then use "/NODEFAULTLIB:xxx.lib" for all the libs in the other rows.
    Code:
    Reusable Library            Switch    Library    Macro(s) Defined
    ----------------------------------------------------------------
    Single Threaded             /ML       LIBC       (none)
    Static MultiThread          /MT       LIBCMT     _MT
    Dynamic Link (DLL)          /MD       MSVCRT     _MT and _DLL
    Debug Single Threaded       /MLd      LIBCD      _DEBUG
    Debug Static MultiThread    /MTd      LIBCMTD    _DEBUG and _MT
    Debug Dynamic Link (DLL)    /MDd      MSVCRTD    _DEBUG, _MT, and _DLL
    So for your debug build, you could add a "/NODEFAULTLIB:xxx.lib" for everthing except MSVCRTD.lib. Then you'll just need to make sure your project settings are setup for /MDd in debug mode.

    gg

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Thanks, I'm pretty sure that's what I tried, but I'll double-check tomorrow.

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Well the DLL seems to work, even with that warning I was getting.

    But, if I ignore (LIBC.lib,LIBCMT.lib,LIBCD.lib,LIBCMTD.lib,MSVCRT. lib) I get these errors:

    Code:
    A.lib(a.obj) : error LNK2001: unresolved external symbol __pctype
    A.lib(a.obj) : error LNK2001: unresolved external symbol ___mb_cur_max
    If I ignore all the above, but add MSVCRTD.lib to the list of libs to include, I get those errors above, as well as these ones:

    Code:
    error LNK2005: _DllMain@12 already defined in msvcrtd.lib(dllmain.obj)
    
    mfcs42ud.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in msvcrtd.lib(dllmain.obj); second definition ignored

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    As for the Release build, it's compiled with the /MT switch, and I'm getting these warnings, but the DLL it built and runs fine:

    Code:
    LINK : warning LNK4098: defaultlib "mfc42u.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
    LINK : warning LNK4098: defaultlib "mfcs42u.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
    LINK : warning LNK4049: locally defined symbol "_free" imported
    LINK : warning LNK4049: locally defined symbol "_malloc" imported
    LINK : warning LNK4049: locally defined symbol "_wcslen" imported
    I'm just ignoring MSVCRT.lib for Release.

    Is it possible to compile cleanly when you're linking with one .lib that uses MFC and another that doesn't? This is one of the reasons I avoid MFC like the plague...

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You should be avoiding Visual Studio 6 like the plague.

  13. #13
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Bubba View Post
    You should be avoiding Visual Studio 6 like the plague.
    Yeah, tell that to my company!

  14. #14
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    Wish I could help more. I've always resolved these issues by making all project settings consitent...

    gg

  15. #15
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Codeplug View Post
    Wish I could help more. I've always resolved these issues by making all project settings consitent...

    gg
    Well I guess as long as it compiles & appears to run properly, I can let MSVC win this time.

    BTW, one other thing I've wondered about .lib files... If a static library (a.lib for example) links with others such as libc.lib, does that mean that a.lib contains all the code from libc.lib, or does it just have something in it that says when you link a.lib with your project that you also need libc.lib?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21