C++ 链接:警告 LNK4098:defaultlib 'MSVCRT' 与其他库的使用冲突;使用 /NODEFAULTLIB:library

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18612072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:04:03  来源:igfitidea点击:

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

c++

提问by Praneeth Kumar Gunda

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 LibraryI have to do this for several other libraries. Which I don't want to. Is there any other Optimal solution.

当我尝试构建与 libeay32.lib 链接的源代码时。我已经从 OpenSSL 源本地构建了这个。我遇到了上面的警告“链接:警告 LNK4098:defaultlib 'MSVCRT' 与使用其他库冲突;使用 /NODEFAULTLIB:library”。当我调试我的 exe 时,只要有一些系统调用(如 read()),exe 就会崩溃。经过一番搜索,我发现这与“运行时库”MT 和 MD 相关。由于某些原因,我无法通过构建 openssl 源来解决此问题。到目前为止,我所做的是在忽略特定库中保留条目“MSVCRT.lib”我必须为其他几个库执行此操作。我不想这样做。有没有其他最佳解决方案。

回答by Rudolfs Bundulis

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 Propertieson 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 DLLin 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.

如果我理解正确,您将 OpenSSL 的发布版本与导致使用不同 CRT 版本的程序的调试版本混合在一起,因为您尚未发布实际设置,因此 OpenSSL 使用 DLL CRT 而您的程序可能更糟代码静态。请发布您的程序使用的是哪种 CRT(可以通过点击Properties项目然后点击 找到Configuration Properties -> C/C++ -> Code Generation -> Runtime Libarary)。要么使用正确的 OpenSSL 版本(例如,使用调试信息构建它并链接到调试 CRT),或者,由于您声明您无法重新编译 OpenSSL,请Multi-threaded DLL在没有优化的情况下编译您的代码,以便您获得一个可以调试并使用相同的程序CRT 作为 OpenSSL。我想这应该可以解决它。

回答by Some programmer dude

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.

Visual Studio 编译器在构建时有两种模式:多线程和非多线程。您在创建项目时设置模式,稍后可以在项目设置中更改它。

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.

这里的问题是这两种模式不兼容。如果您混合使用多线程库和非多线程库,那么您会遇到类似的错误。要么使用其他模式重新编译其他库,要么更改项目的模式以匹配库的模式。

回答by Przemyslaw Szeptycki

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).

问题是您将应用程序动态链接到 VS 中的运行时 /MD(默认情况下,这意味着您应该为您的应用程序提供 Visual Studio Redistributable Package)。

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

属性 -> 配置属性 -> C/C++ -> 代码生成 -> 运行时库

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.

而默认情况下,opensll 库静态链接到运行时(运行时包含例如 STL 的实现)。混合运行时链接因此警告是不好的。您可以通过使用动态链接到运行时重新编译 opensll 库来解决该问题。

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

请遵循:http: //developer.covenanteyes.com/building-openssl-for-visual-studio/然后在

ms\nt.mak

ms\nt.mak

change \MTto \MDbefore running nmake -f ms\nt.makand nmake -f ms\nt.mak install

更改\MT\MD运行前nmake -f ms\nt.maknmake -f ms\nt.mak install

回答by pag3faul7

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

当使用不同风格的 Microsoft C-Runtime 库时会出现这种冲突。这是一个概述: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.

因此,如果您链​​接到 msvcrt.lib(动态、多线程 CRT)并且您的依赖项之一与 libcmtd.lib(静态、多线程)链接,则会出现此警告。这种情况可能会导致细微的错误,并可能导致难以调试的各种问题。除了将冲突库设置为忽略列表并希望在您无法控制依赖项的情况下获得最好的结果之外,没有什么可以消除警告的了。通常,对所有依赖项和程序本身使用相同的 C/C++ 运行时链接是一个好主意。