The default Library "LIBCMTD" conflicts with other libraries; please use/NODEFAULTLIB:LIBRARY__VC

Source: Internet
Author: User
Tags openssl

from:http://blog.csdn.net/pgmsoul/article/details/4203941

Often encountered this warning message, because the operation is not a problem, so did not delve into. But the success of the "0 mistakes, 0 warnings" was a bit of an online search. The original problem is on the default library reference selection.

VS2008, Project--Properties--Configuration Properties--c/c++--code generation: He has/mt,/mtd,/md,/mdd four options, you have to have all the libraries use the same configuration, otherwise there will be the corresponding prompts, and may even appear unresolved functions. Sometimes we use libraries that are not controlled by ourselves, so we can only set the engineering attributes to the same options as the libraries you use.

Error 1 LNK2005: _free already defined in LIBCMTD.lib (dbgheap.obj) MSVCRT.lib

Error 2 LNK2005: _malloc already defined in LIBCMTD.lib (dbgheap.obj) MSVCRT.lib

.....

If there is a bunch of redefinition errors in the same lib, and it conflicts with the same LIB, then this two Lib function should be the same, you can choose one of the 2, as long as the "ignore a specific library" to fill in the need to ignore the library.

Project Properties-Configuration Properties-linker-input-ignores specific libraries: libcmtd.lib

Project Properties-Configuration Properties-use of general-MFC: using MFC in shared DLLs

The conflict between MSVCRT.lib and LIBCMT.lib is still more common.

As you can see from the error message, symbols such as __isctype are repeatedly defined in the msvcrt.lib and LIBCMT.lib libraries. Why is there such a problem? This will be from the role of the two libraries to talk about.

MSVCRT.lib is the multithreaded DLL version of the C Run-time Library in VC, and LIBCMT.lib is the multithreaded Run-time library. In the same project, all source files must be linked to the same C Run-time library. If a file uses a multithreaded DLL version, and other files use a single-threaded or multithreaded version of the library, which means that a different library is used, this warning can occur.

The meaning of the alarm information after we know it, we need to find the cause of the problem. In the project setup we can see that the current project is using a multithreaded version of the runtime library, which means that there are other files in the project that are not in this version of the runtime library. Obviously, it's OpenSSL's static library. Looking at the Nt.mak under MS in OpenSSL, we can find that the static library version OpenSSL compiled using the compile switch/MD, that is, the OpenSSL static library is the default multithreaded DLL version of the C Run-time library.

The reason has been found. The solution, obviously, is two. In short, the runtime library of two projects is unified.

The simple way is to modify the project's dynamic library to use the multithreaded DLL version of the C Run-time library.
In some cases your project may not change the current Run-time library, you can modify the/MD switch in the OpenSSL Nt.mak to/MT and recompile the OpenSSL static library.

The default Library "library" conflicts with other libraries; Please use the/nodefaultlib:library LNK4098 solution

You are trying to link to an incompatible library.

Attention
The Run-time library now contains instructions that prevent the blending of different types. You receive this warning if you try to use a different type of Run-time library in the same program or use a debug and debug version of the Run-time library. For example, you will get this warning if you compile a file to use one of the Run-time libraries, and then compile another file to use another Run-time library, such as a single-threaded run-time library for multithreaded Run-time libraries, and try to link them. All source files should be compiled to use the same Run-time library. For more information, see Using Run-time libraries (/MD,/MT, and/LD) compiler options.


You can use the linker's/verbose:lib switch to determine which library the linker is searching for. If you receive LNK4098 and you want to create an executable file that uses a single-threaded, debug Run-time library, use the/VERBOSE:LIB option to determine which library the linker is searching. Instead of LIBCMT.lib, MSVCRT.lib, LIBCD.lib, LIBCMTD.lib, and MSVCRTD.lib, the linker should output LIBC.lib as a search library. You can use/NODEFAULTLIB for each library you want to ignore to tell the linker to ignore the wrong Run-time library.

The following table shows the libraries that should be ignored depending on which Run-time library you want to use.


To use the first row of run-time libraries, ignore these libraries on line 2nd
Single Thread (libc.lib)
LIBCMT.lib, MSVCRT.lib, LIBCD.lib, LIBCMTD.lib, Msvcrtd.lib

Multithreading (LIBCMT.lib)
LIBC.lib, MSVCRT.lib, LIBCD.lib, LIBCMTD.lib, Msvcrtd.lib

Multithreading using DLLs (MSVCRT.lib)
LIBC.lib, LIBCMT.lib, LIBCD.lib, LIBCMTD.lib, Msvcrtd.lib

Debug single Thread (LIBCD.lib)
LIBC.lib, LIBCMT.lib, MSVCRT.lib, LIBCMTD.lib, Msvcrtd.lib

Debugging multithreading (LIBCMTD.lib)
LIBC.lib, LIBCMT.lib, MSVCRT.lib, LIBCD.lib, Msvcrtd.lib

debugging multithreading using DLLs (Msvcrtd.lib)
LIBC.lib, LIBCMT.lib, MSVCRT.lib, LIBCD.lib, LIBCMTD.lib


For example, if you receive this warning and you want to create an executable file that uses a debug, single-threaded version of the Run-time library, you can use the following options with the linker:


/nodefaultlib:libcmt.lib/nodefaultlib:msvcrt.lib/nodefaultlib:libcd.lib/nodefaultlib:libcmtd.lib/nodefaultlib: Msvcrtd.lib

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.