如何强制MSVC ++忽略静态库的CRT依赖?

[英]How can I force MSVC++ to ignore CRT dependencies of a static library?


I don't know if it's possible to do this, but I would like the /NODEFAULTLIB to be applied to a static library project.

我不知道是否可以这样做,但我希望将/ NODEFAULTLIB应用于静态库项目。

I have many application projects (A.exe, B.dll, C.dll) that use a common static library D.lib. This library has a lot of code and also has other .lib dependencies as well. One of them is the openssl library, which seems to have been built for win32 against the Release version of the CRT (i don't have the original project/sources).

我有许多使用公共静态库D.lib的应用程序项目(A.exe,B.dll,C.dll)。这个库有很多代码,也有其他.lib依赖项。其中一个是openssl库,它似乎是针对CRT的Release版本为win32构建的(我没有原始项目/来源)。

So far, to avoid the mixing of the Release/Debug versions of CRT, I have to put the /NODEFAULTLIB:msvcrt.lib linker directive in all leaf projects (A.exe, B.dll). This works but I think it's not the ideal way of dealing with that issue. I tried to put this property in D.lib project, but it has no effect.

到目前为止,为了避免混合使用CRT的Release / Debug版本,我必须将/NODEFAULTLIB:msvcrt.lib链接器指令放在所有叶子项目(A.exe,B.dll)中。这有效,但我认为这不是处理这个问题的理想方式。我试图将此属性放在D.lib项目中,但它没有任何效果。

Is there a way to force msvc++ to ignore the msvcrt.lib dependency from the 3rd party library?

有没有办法强制msvc ++忽略来自第三方库的msvcrt.lib依赖?

3 个解决方案

#1


A .lib does not have any linker settings because you don't link it, you link to it. A .lib is just an archive of .obj files, sort of like an uncompressed .zip file - that's why you have to put the setting on all projects that link to it.

.lib没有任何链接器设置,因为您没有链接它,您链接到它。 .lib只是.obj文件的存档,有点像未压缩的.zip文件 - 这就是为什么你必须将设置放在链接到它的所有项目上。

If you're using VS2005+ you could use property sheets so that you only have to put the setting in one place and then use that property sheet in all projects.

如果您使用的是VS2005 +,则可以使用属性表,这样您只需将设置放在一个位置,然后在所有项目中使用该属性表。

However, OpenSSL is just that - Open Source, so you should be able to get the source for the version you are using and build it again (and add it to your version control system of course). I thought OpenSSL could be built as a DLL or LIB, which would solve your problem as the DLL would not interfere with the linking of your code.

但是,OpenSSL只是 - 开源,所以你应该能够获得你正在使用的版本的源代码并再次构建它(当然,将它添加到你的版本控制系统)。我认为OpenSSL可以构建为DLL或LIB,这将解决您的问题,因为DLL不会干扰您的代码链接。

Failing that, you always have the option of slitting your functionality out into a separate DLL so that you only have issues with one project.

如果做不到这一点,您总是可以选择将您的功能分解为单独的DLL,这样您只会遇到一个项目的问题。

#2


My understanding is that if library LIB in linked statically into a DLL, the DLL contains already all relevant code from LIB. Therefore, this coupling cannot be removed. This is just based on my understanding of statical linking, not on experiments.

我的理解是,如果库LIB静态链接到DLL中,则DLL包含来自LIB的所有相关代码。因此,不能消除这种耦合。这只是基于我对静态链接的理解,而不是基于实验。

#3


To prevent your distributed static link library from depending on a specific MSVC runtime library you need to set this compiler option (in Visual Studio 2010 it looks like):

要防止分布式静态链接库依赖于特定的MSVC运行时库,您需要设置此编译器选项(在Visual Studio 2010中看起来像):

Configuration Properties -> C/C++ -> Advanced -> Omit Default Library Name = Yes (/ZI)

配置属性 - > C / C ++ - >高级 - >省略默认库名称=是(/ ZI)

Now your users can link to your release built static lib from their debug build and not try to link to the incorrect runtime library causing problems, as well as linkers warnings.

现在,您的用户可以从他们的调试版本链接到您的发布版本的静态库,而不是尝试链接到不正确的运行时库导致问题,以及链接器警告。

Note that may cause link errors if your library actually depends on a specific runtime library or its behavior, and compatible components are not provided in some other way.

请注意,如果库实际上依赖于特定的运行时库或其行为,则可能会导致链接错误,并且不会以其他方式提供兼容的组件。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/03/26/d359e1cd3ae920b2cbdfc68f71701a42.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告