Msvcrtd. Lib conflicts with libcmtd. Lib.

Source: Internet
Author: User

Vs2005 link problem: lnk2005 error: Error lnk2005: _ free has been defined in libcmtd. Lib (dbgheap. OBJ)

This warning message is often encountered in the past, because there is no problem in the operation, so I did not go into details. However, I searched the internet for the success prompt "0 errors and 0 warnings. The original problem lies in the reference selection of the default library.

Vs2008, project -- Property -- configuration Property -- C/C ++ -- code generation: it has four options:/mt,/MTD,/MD,/MDD, you must use the same configuration for all the databases you are using. Otherwise, a prompt may appear, or even a function that cannot be parsed. Sometimes the library we use is not controllable by ourselves, so we can only set the project attributes to the same option of the library you use.

Error 1 error lnk2005: _ free has defined msvcrt. Lib in libcmtd. Lib (dbgheap. OBJ)

Error 2 error lnk2005: _ malloc has defined msvcrt. Lib in libcmtd. Lib (dbgheap. OBJ)

.....

If a bunch of redefinition errors occur in the same lib and conflict with it is the same Lib, the functions of the two lib should be the same. You can select either of them, you only need to enter the databases to be ignored in "ignore specific databases.

Project properties-configuration properties-linker-input-ignore specific libraries: libcmtd. Lib

Project properties-configuration properties-General-Use of MFC: use MFC in shared DLL

Conflicts between msvcrt. lib and libcmt. Lib are still common.

The error message shows that the _ isctype and other symbols are repeatedly defined in the msvcrt. lib and libcmt. Lib libraries. Why is this problem? This will start with the role of the two databases.

Msvcrt. Lib is the C Runtime Library of multithreaded DLL in VC, while libcmt. Lib is the Runtime Library of multithreaded. In the same project, all source files must be linked to the same C Runtime Library. If a file uses the multithreaded dll version, and other files use the single-threaded or multithreaded version library, that is to say, different libraries will cause this warning.

After we understand the meaning of the alarm information, we need to find the cause of the problem. In the project settings, we can see that the current project uses the multithreaded non-dll version of The Runtime Library, which indicates that there are other files in the project using the Runtime Library of another version. Obviously, it is the static library of OpenSSL. View the NT under MS in OpenSSL. mak, we can find that OpenSSL uses the compilation switch/MD for compiling in the static library version, that is, the OpenSSL static library is the default C Runtime Library of the multithreaded dll version.

The cause is found. There are obviously two solutions. In short, the runtime libraries of the two projects are unified.

The simple method is to change the dynamic library of the project to the C Runtime Library of multithreaded dll version.

In some cases, your project may not change the current Runtime Library. You can change the/MD switch in the OpenSSL nt. Mak to/MT and re-compile the OpenSSL static library.

The default library "library" conflicts with other libraries. Use the/nodefaultlib: Library lnk4098 solution.

You are attempting to link to an incompatible library.

Note:

The Runtime Library now contains commands that prevent mixing different types of commands. This warning is reported if you try to use different types of runtime libraries in the same program or use runtime libraries of debug and non-DEBUG Versions. For example, if you compile a file to use one Runtime Library, and compile another file to use another Runtime Library (for example, single-thread Runtime Library for multi-thread Runtime Library ), and try to link them, this warning will be obtained. All source files should be compiled to use the same Runtime Library. For more information, see use the Runtime Library (/MD,/mt, And/LD) compiler options.

You can use the/verbose: Lib switch of the linker to determine the library to search. If you receive lnk4098 and want to create executable files that use a single thread or a non-Debug Runtime Library, use the/verbose: Lib option to determine the library that the linker searches. The linker outputs libc. Lib as the Search Library, instead of libcmt. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib, and msvcrtd. Lib. You can use/nodefalib Lib for each library to be ignored to notify the linker to ignore the wrong Runtime Library.

The following table shows the databases to be ignored Based on the Runtime library to be used.

To use the first row of Runtime Library, ignore these libraries in row 2nd

Single thread (libc. Lib)

Libcmt. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib, and msvcrtd. Lib

Multithreading (libcmt. Lib)

Libc. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib, and msvcrtd. Lib

Multiple Threads Using DLL (msvcrt. Lib)

Libc. Lib, libcmt. Lib, libcd. Lib, libcmtd. Lib, and msvcrtd. Lib

Debug a single thread (libcd. Lib)

Libc. Lib, libcmt. Lib, msvcrt. Lib, libcmtd. Lib, and msvcrtd. Lib

Debug multiple threads (libcmtd. Lib)

Libc. Lib, libcmt. Lib, msvcrt. Lib, libcd. Lib, and msvcrtd. Lib

Multi-thread Debugging Using DLL (msvcrtd. Lib)

Libc. Lib, libcmt. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib

For example, if you receive this warning and want to create an executable file that uses a non-debug, single-threaded version of The Runtime 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

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/pgmsoul/archive/2009/05/20/4203941.aspx

What have the linker done below? Writing is quite successful!

 

 

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.