“链接库依赖关系”是什么意思?链接器选项实际上在 Visual Studio 2010 - 2015 及更高版本中起作用吗?
到 VS2008,您可以在解决方案文件中设置本机 C++ 项目依赖项 (Project Dependencies ...
),并且如果(默认情况下)
Properties -> Linker -> General : Link Library Dependencies = Yes
设置了链接器选项,则Visual Studio Build 将自动链接到该项目所依赖的所有项目(DLL、LIB)的 .lib
文件,该项目将被“静态”链接。
Side 注:微软更改了依赖项在 VS2010 中的工作方式,您现在应该将依赖项直接添加到项目中,
Common Properties -> Framework and References : (List of depenencies)
(each lib/dll has a separate option:
Project Reference Properties -> Link Library Dependencies : True|False
我对此很满意。 这不是这个问题的意思。
(这里有一个解释:灵活的项目到项目引用。)
但是仍然可以定义项目对解决方案级别的依赖关系常规
链接器选项也仍然在那里。然而它不起作用。请参阅:
- 链接库依赖项不工作吗?
- Visual Studio 2010 是否破坏了 C++ 项目之间的“项目依赖关系”?< /一>
- <一href="https://stackoverflow.com/questions/3795567/visual-studio-2010-not-autolinking-static-libraries-from-projects-that-are-depend">Visual Studio 2010 不会自动链接以下项目中的静态库是应该有的依赖关系
,特别是参见此处(实际问题如下)
Microsoft 确认链接器选项没有达到世界上其他人期望的效果,并添加了以下解释:
感谢您报告此反馈。您遇到的问题是 通过设计。 “链接库依赖关系”是一个标志,仅规定 是否将库作为输入传递给链接器。确实如此 不会自动找到依赖关系。作为客户,您必须 按照您的建议手动定义依赖关系。
谁能解释一下这意味着什么,或者更切中要害:“Link Library Dependency”链接器选项在 Visual Studio 2010 中实际执行什么操作?
什么是“输入到实际未链接的链接器”应该是什么?
Up to VS2008, you set your native C++ project dependencies up in the solution file (Project Dependencies ...
) and if (by default) the Linker Option
Properties -> Linker -> General : Link Library Dependencies = Yes
is set, the Visual Studio Build will automatically link in the .lib
files of all projects (DLLs, LIBs) that this project is dependent on will be "statically" linked in.
Side Note: Microsoft changed how the dependencies worked in VS2010 and you are now supposed to add the dependency directly to the project
Common Properties -> Framework and References : (List of depenencies)
(each lib/dll has a separate option:
Project Reference Properties -> Link Library Dependencies : True|False
I'm fine with that. This is not what this question is about.
(One explanation here: Flexible Project-to-Project References.)
It is still possible however to define project dependencies on the Solution level and the General
Linker option is also still there. However it doesn't work. See:
- Link Library Dependencies not working?
- Did Visual Studio 2010 break "Project Dependencies" between C++ projects?
- Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to
and especially see here (acutal question follows)
Where Microsoft confirms that the Linker Option doesn't do what the rest of the world's population expects it to do, and adds the following explanation:
Thanks for reporting this feedback. The issue you are experiencing is
by design. "Link Library Dependency" is a flag that only dictates
whether or not to pass the library as an input to the linker. It does
not find the dependency automatically. As a customer you will have to
define the depedency manually as you suggest.
Can anyone explain what that means, or more to the point: What does the "Link Library Dependency" linker option actually do in Visual Studio 2010?
What is an "input to the linker" that isn't actually linked supposed to be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须为设置提供正确的值以使其清晰:
You have to give the setting the proper value to bring clarity:
2017年重新运行。耶。
TL;DR
此选项为每个项目引用上的实际
链接库依赖项
设置默认值(a)。如果每个项目引用都设置了LinkLibraryDependecies
,那么它实际上毫无意义。但是,添加新引用时,默认情况下(在 VS2010 和 2015 中)
vcxproj
文件中的新
元素不会已设置设置,因此此选项是相关的,因为它为所有新添加的引用提供默认值,只要它们的值未被修改。(a):对于所有配置(调试/发布)和平台(Win32/x64),确实应该是相同的,否则事情会变得非常复杂。
血淋淋的细节
Hans指出它似乎在VS2010中没有做任何事情 。然而,这并不意味着 VS/MSBuild 实际上不使用它。
关键在于如何将此选项插入到
vcxprj
文件中,以及默认值如何在 msbuild 文件中的
设置中发挥作用。如上所示的链接器对话框中的设置插入为:
虽然它似乎以某种方式与
Link
选项组合在一起,但事实就是如此来迷惑你。在给定的
vcxproj
文件(或来自.props
文件)中,它的实际作用是设置默认值VS2010 VC 设置对话框中的框架和引用
部分中每个项目依赖项的链接库依赖项
值 --——或者在 VS2015 参考的子树中——
中的链接库">
这是相关的,因为当您添加新的项目引用时,默认条目您的
vcxproj
文件将如下所示:您会注意到此处缺少
true|false
子元素:这意味着您的“全局”设置实际上将用于设置默认值。如果您的全局设置为
false
(或No
),则项目引用不会链接到任何内容。如果为true
,它将链接。此外:
LinkLibraryDependency
,它将默认为 true (来自 MSBuild 文件夹中的Microsoft.Cpp[.Common].props
文件)。This is notused
,这将被解释为 true。False is the new true!
,或者在此设置中No way
,它也会被解释为true建造。false
除外,即使在构建项目时这被解释为true。更重要的是:
似乎在使用
vcproj
文件转换旧解决方案时,转换器将采用sln
中指定的旧依赖项并vcproj
项目的 Linker 选项的值,并实际为插入新vcxproj
的每个ProjectReference
设置LinkLibraryDependency
> - 这就是我长期以来认为这是一个死选项的原因之一 - 我们的大多数项目都有可以追溯到 VS2005 的转换历史。2017 Re-Run. Yay.
TL;DR
This Option sets the default value(a) for the actual
Link Library Dependecies
on each project reference. If each project reference hasLinkLibraryDependecies
set, then it is in effect meaningless.However, when adding a new reference, by default (in VS2010 and 2015) the new
<ProjectReference>
element in thevcxproj
file does not have the setting set, so this option is relevant in that it provides the default for all newly added references, as long as their value isn't modified.(a): It really should be the same for all Configurations (Debug/Release) and Platforms (Win32/x64) or things get really complicated.
Gory details
Hans pointed out that it appears to not do anything in VS2010 as such. However, this doesn't mean that it actually ain't used by VS/MSBuild.
The crux is how this option is inserted into the
vcxprj
file and how the defaults work for the<ProjectReference>
setting in the msbuild file.The setting on the Linker dialog as shown above is inserted as:
And while it appears to be somehow grouped together with the
Link
Option, that's just there to confuse you.What this actually does in a given
vcxproj
file (or when coming from a.props
file), is to set the default value of theLink Library Dependencies
Value for each project dependency on theFrameworks and References
section in a VS2010 VC settings dialog ---- or in the subtree of the VS2015 References --
And this is relevant, because when you add a new project reference, the default entry in your
vcxproj
file will look like this:You'll notice that the
<LinkLibraryDependecies>true|false</..>
sub element is missing here: This means you "global" setting will actually be used to set the default value.If your global setting is
false
(orNo
), the project reference won't link in anything. If it'strue
, it will link in.What's more:
LinkLibraryDependency
, is completely missing from your settings, it will default to true (from theMicrosoft.Cpp[.Common].props
file in the MSBuild folder).This is not used
in your global setting, this will be interpreted as true.False is the new truth!
, or maybeNo way
in this setting, it will also be interpreted as true by the build.false
, even though this is then interpreted as true when building the project.What's even more:
It seems that when converting old Solutions with
vcproj
files, the converter will take the old dependencies that were specified in thesln
and the value of thevcproj
project's Linker option, and actually set theLinkLibraryDependency
for eachProjectReference
it inserts into the newvcxproj
- thats one reason I thought that this is a dead option for so long - most of our projects have a conversion history dating back to VS2005.这里的事情是你必须去,项目属性 - >共同属性->框架和参考,然后向您的项目添加新参考。那么只有它才能在 VS 2010 中工作,而不是像在 VS 的早期版本中那样
Here the thing is you have to go to, project properties -> common properties -> framework and references and then add new reference to your projects. Then only it will work in VS 2010 not like in early versions of VS
这必须在
Properties / Common / Frameworks and References
中设置。或者,您可以在 vcxproj 文件中添加类似下面的内容,当然使用您引用的实际项目及其 uuid项目。
This has to be set in the
Properties / Common / Frameworks and References
Alternatively you can add something like the thing below in your vcxproj file, of course use the actual project you're referencing and the uuid of that project.
看来您还必须
在 REFERENCED 项目中进行设置。
It seems like you also have to set
in the REFERENCED project.