VS2010静态链接问题 [英] VS2010 static linking issue

查看:495
本文介绍了VS2010静态链接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司最近从VS2005升级到VS2010。我们有一个巨大的项目,它使用了很多模块,被静态链接到exe。但是在VS2010中似乎有一些链接问题。



为了解释我们的问题,我们构建了一个最小的示例项目,如图所示: / p>



有一个应用程序使用库A中的一个函数。库A调用每个库B和库C的一个函数。这两个库调用库D提供的函数。



对于框架和引用下的 Exe 1 ,我们将所有内容设置为 false / em>,设置为true。添加的唯一引用是链接到库A 。对于每个库,所有设置都设置为false。库A仅获取对 B C 的引用,以及这两个仅获取 D 的引用。 库D 没有引用。



在构建应用程序时,它没有问题。应用程序注意到,库A正在使用库B和C,它们使用库D,因此它知道它必须链接这些库。这些库链接到exe没有问题。



现在我们改变一些东西,比如库D 。只是有点不同,只有一个字母。现在我们再次尝试构建应用程序,它注意到更改并重新编译库D ,但是:它不再链接到它。结果是库B C 中的链接错误,因为它们使用库D 。我们必须先执行重建,以强制完成建设,然后然后重新链接所有内容。



这发生在最小的例子以及我们的主要项目。当然,我们可以添加每个库作为exe的附加依赖,但它将是很好的,如果它将工作,就像它第一次构建项目时,并在代码中的更改后继续工作。我们注意到,当将使用库依赖关系输入设置为 true 时,它会再次工作,但不会链接* .lib文件,当然不是我们想要的。



有没有人有类似的经历或有任何人有这个问题的解决方案?这是VS2010的错误行为吗?



TIA。



ps:所有库和可执行文件都是本机C ++。






编辑(解决方法: this site



%ProgramsFile%\MSBuild\Microsoft.cpp\v4.0\Microsoft.CPPBuild.Targets 文件中有一行

 < Target Name =GetResolvedLinkLibsReturns =@(LibFullPath)DependsOnTargets =$(CommonBuildOnlyTargets)> 

如果将此行更改为

 < Target Name =GetResolvedLinkLibsReturns =@(LibFullPath)DependsOnTargets =$(CommonBuildOnlyTargets); ResolvedLinkLib> 

链接正常工作,所有需要的libs都隐式链接。链接器输出不仅显示lib_a.lib,而且显示所有其他链接的库lib_b,lib_c,lib_d,而不需要手动将它们作为依赖项添加到exe。



更多的解决方案,然后一个解决方案,也许有一个正确的方法来实现隐式链接。

解决方案



Visual Studio 2010不能自动将静态库与依赖应用的项目自动链接



2010年链接库依赖关系的行为



构建一个VC ++项目时使用链接的静态库依赖关系的未解决的外部项目



弹性项目 - 项目参考


my company has recently upgraded from VS2005 to VS2010. We have a huge project which uses a lot of modules which are being linked statically into the exe. But there seem to be some issues with linking in VS2010.

To explain our problem, we've built a minimal example project which is composed as shown on this graphic:

There is an application using one function from library A. Library A calls one function of each library B and library C. Those two libraries call a function provided by library D.

For Exe 1 under Framework and References we set everything to false except for Link Library Dependencies which is set to true. The only reference added is linking to library A. For each of the libraries all the settings are set to false. Library A gets references to only B and C, as well as those two getting references to D only. Library D has no references.

When building the application it works without problems. The application notices that library A is using library B and C which are using library D, so it knows it has to link those libraries, too. The libs are linked into the exe without problems.

Now we change something in, let's say, library D. Just a little difference, only one letter. Now we try to build the application again, it notices the change and re-compiles library D, but: It doesn't link to it anymore. The result are linking errors in library B and C, because they use library D. We have to run Rebuild first, in order to force the complete building and then everything is linked again.

This happens for both the minimal example as well as for our main project. Of course, we can add each of the libraries as additional dependency for the exe but it would be nice if it would work just like it does when building the project for the first time and continue to work after changes in the code. We noticed that when setting Use Library Dependency Inputs to true, that it works again, but then it doesn't link the *.lib files but the *.obj files which is not what we want of course.

Has anyone made similar experiences or has anyone a solution for this issue? Is this a buggy behavior of VS2010?

TIA.

p.s.: All libraries and executables are native C++.


Edit: (Workaround taken from this site)

In the file %ProgramsFile%\MSBuild\Microsoft.cpp\v4.0\Microsoft.CPPBuild.Targets there is a line

<Target Name="GetResolvedLinkLibs" Returns="@(LibFullPath)" DependsOnTargets="$(CommonBuildOnlyTargets)">

If you change that line to

<Target Name="GetResolvedLinkLibs" Returns="@(LibFullPath)" DependsOnTargets="$(CommonBuildOnlyTargets);ResolvedLinkLib">

the linking works properly and all needed libs are linked to implicitly. The linker output not only shows lib_a.lib but also all other chained libs, lib_b, lib_c, lib_d without having them added manually as dependencies to the exe.

This seems to be more a workaround then a solution, maybe there is a proper way to achieve implicit linking.

解决方案

Have a look at following links:

Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to

Behavior of Link Library Dependencies in 2010

Unresolved Externals When Build a VC++ Project with Chained Static Lib Dependencies

Flexible Project-to-Project References

这篇关于VS2010静态链接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆