Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

Tags:

c++

When I try to build my sources linking with libeay32.lib. I have built this locally from OpenSSL sources. I encountered the above warning "LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library". When I debug my exe, whenever there is some system call (like read()), Exe crashes. After some search, I could find that this is some thing related to 'Runtime Library' MT and MD. I can't fix this by building openssl sources due to some reasons. As of now, what I did is I kept the entry "MSVCRT.lib" at Ignore Specific Library I have to do this for several other libraries. Which I don't want to. Is there any other Optimal solution.

like image 449
Praneeth Kumar Gunda Avatar asked Sep 04 '13 11:09

Praneeth Kumar Gunda


4 Answers

If i understand it right you are mixing a release version of OpenSSL with a debug version of your program that causes different CRT versions to be used, since you haven't posted actual settings it may be even worse that OpenSSL is using DLL CRT while your code static. Please post what kind of CRT is your program using (can be found by clicking Properties on the project and then Configuration Properties -> C/C++ -> Code Generation -> Runtime Libarary). Either use proper OpenSSL version (e.g. build it with debug info and linked to debug CRT) or, since you are stating you cannot recompile OpenSSL, compile your code with Multi-threaded DLL in release without optimizations so you get a program that can be debugged and uses the same CRT as OpenSSL. That should solve it I guess.

like image 73
Rudolfs Bundulis Avatar answered Nov 13 '22 23:11

Rudolfs Bundulis


The Visual Studio compiler have two modes when building: Multi-threaded and not multi-threaded. You set the mode when you create a project, and can change it later in project settings.

The problem here is that these two modes are not compatible. If you mix multi-thrading and non-multi-threading libraries then you will get errors like those you have. Either recompile the other library with the other mode, or change the mode of your project to match that of the library.

like image 39
Some programmer dude Avatar answered Nov 13 '22 23:11

Some programmer dude


This conflict comes up when using different flavors of the Microsoft C-Runtime libraries. Here is an overview: http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx

So f.e. if you are linking to msvcrt.lib (dynamic, multithreaded CRT) and one of your dependencies is linked against the libcmtd.lib (static, multithreaded) this warning comes up. This situation may lead to subtle errors and can cause all sort of problems which are hard to debug. There is not much you can do to get rid of the warning than set the conflicting library to the ignore list and hope for the best if you have no control over the dependencies. In general it is a good idea to use the same C/C++ runtime linkage for all dependencies and the program itself.

like image 3
pag3faul7 Avatar answered Nov 13 '22 22:11

pag3faul7


The thing is that you are linking your application to the runtime dynamically /MD in the VS (by default, which means that you should provide the Visual Studio Redistributable Package with your app).

Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library

Whereas the opensll lib by default links to the runtime statically (runtime contains for example the implementation of the STL). It is not good to mix the runtime linking thus the warning. You can fix the problem by recompiling the opensll library using dynamic linking to the runtime.

Please follow: http://developer.covenanteyes.com/building-openssl-for-visual-studio/ then in the

ms\nt.mak

change \MT to \MD before running nmake -f ms\nt.mak and nmake -f ms\nt.mak install

like image 3
Przemyslaw Szeptycki Avatar answered Nov 14 '22 00:11

Przemyslaw Szeptycki