Warning lnk4098: defaultlib "msvcrt" conflicts with use of other libs; Use/nodefaultlib

Source: Internet
Author: User

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 make all the databases used use the same configuration, otherwise there will be a corresponding prompt, 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

 

 

 

 

========================================================== ======================================

 

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

Linker tools warning lnk4098
Defaultlib "library" conflicts with use of other libs; Use/nodefaultlib: Library

You are trying to link with incompatible libraries.

Important the run-time libraries now contain ctictives to prevent mixing different types. you'll receive this warning if you try to use different types or debug and non-DEBUG Versions of the run-time library in the same program. for example, if you compiled one file to use one kind of run-time library and another file to use another kind (for example, single-threaded versus multithreaded) and tried to link them, you'll get this warning. you shoshould compile all source files to use the same run-time library. see the use run-time Library (MD,/ml,/mt,/LD) compiler options for more information.

You can use the linker's/verbose: Lib switch to determine which libraries the linker is searching. if you receive lnk4098 and want to create an executable file that uses, for example, the single-threaded, non-Debug run-time libraries, use the/verbose: lib option to find out which libraries the linker is searching. the linker shoshould print libc. lib and not libcmt. lib, msvcrt. lib, libcd. lib, libcmtd. lib, or msvcrtd. lib as the libraries searched. you can tell the linker to ignore the incorrect run-time libraries by typing the incorrect libraries in the ignore libraries text box on the Link Tab Of the Settings dialog box in developer's studio or by using the/nodefalib Lib: library option with link for each library you want to ignore. see the ignore libraries (/nodefaultlib) linker option for more information.

The table below shows which libraries shoshould be ignored depending on which run-time library you want to use.

To use this run-time library ignore these libraries
Single-threaded (libc. Lib) libcmt. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib, msvcrtd. Lib
Multithreaded (libcmt. Lib) libc. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib, msvcrtd. Lib
Multithreaded Using DLL (msvcrt. Lib) libc. Lib, libcmt. Lib, libcd. Lib, libcmtd. Lib, msvcrtd. Lib
Debug single-threaded (libcd. Lib) libc. Lib, libcmt. Lib, msvcrt. Lib, libcmtd. Lib, msvcrtd. Lib
Debug multithreaded (libcmtd. Lib) libc. Lib, libcmt. Lib, msvcrt. Lib, libcd. Lib, msvcrtd. Lib
Debug multithreaded Using DLL (msvcrtd. Lib) libc. Lib, libcmt. Lib, msvcrt. Lib, libcd. Lib, libcmtd. Lib

For example, if you have Ed this warning and you want to create an executable file that uses the non-debug, single-threaded version of the run-time libraries, you cocould use the following options with the linker:

/Nodefaultlib: libcmt. lib/nodefaultlib: msvcrt. lib/nodefaultlib: libcd. lib/nodefaultlib: libcmtd. lib/nodefaultlib: msvcrtd. Lib

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

You are attempting to link to an incompatible library.

Important: The Runtime Library now contains instructions to prevent mixing different types. 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,/ml,/mt,/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 this Runtime Library, ignore these libraries.
Single-threaded (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
Use multi-threaded DLL (msvcrt. Lib) libc. Lib, libcmt. Lib, libcd. Lib, libcmtd. Lib, and msvcrtd. Lib
Debug 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
Use DLL debugging multithreading (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

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.