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

后端 未结 4 1469
感情败类
感情败类 2021-02-05 12:06

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 \'

相关标签:
4条回答
  • 2021-02-05 12:08

    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.

    0 讨论(0)
  • 2021-02-05 12:13

    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.

    0 讨论(0)
  • 2021-02-05 12:19

    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

    0 讨论(0)
  • 2021-02-05 12:35

    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.

    0 讨论(0)
提交回复
热议问题