“链接库依赖"有什么作用?链接器选项实际上在 Visual Studio 2010 - 2015 及更高版本中执行吗? [英] What does the "Link Library Dependency" linker option actually do in Visual Studio 2010 - 2015 and upwards?

查看:21
本文介绍了“链接库依赖"有什么作用?链接器选项实际上在 Visual Studio 2010 - 2015 及更高版本中执行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VS2008 之前,您在解决方案文件 (Project Dependencies ...) 中设置本机 C++ 项目依赖项,并且如果(默认情况下)链接器选项

属性 ->链接器 ->常规:链接库依赖项 = 是

设置后,Visual Studio Build 将自动链接到该项目所依赖的所有项目(DLL、LIB)的 .lib 文件中.链接进来.


侧面注意:Microsoft 更改了 VS2010 中依赖项的工作方式,您现在应该将依赖项直接添加到项目中>

通用属性 ->框架和参考:(依赖列表)(每个 lib/dll 都有一个单独的选项:项目参考属性 ->链接库依赖项:True|False

我没问题.不是这个问题的内容.

(这里有一个解释:

...<项目定义组><Cl编译>...</ClCompile><链接>...</链接><项目参考><LinkLibraryDependencies>VS 2010 不使用此选项!</LinkLibraryDependencies></项目参考>...</ItemDefinitionGroup></项目>

虽然它似乎以某种方式与 Link 选项组合在一起,但这只是让您感到困惑.

在给定的 vcxproj 文件(或来自 .props 文件时)实际上设置VS2010 VC 设置对话框中 Frameworks and References 部分中每个项目依赖项的 Link Library Dependencies Value 的默认值 --

-- 或在 VS2015 References 的子树中 --

这是相关的,因为当您添加新的项目引用时,vcxproj 文件中的默认条目将如下所示:

<代码>...<项目组><ProjectReference Include="..W32DynLib1W32DynLib1.vcxproj"><项目>{96be134d-acb5-....-..-....bb6fe4a7}</项目></项目参考></项目组>

您会注意到 true|false</..> 子元素在此处丢失:这意味着您的全局"设置实际上将用于设置默认值价值.

如果您的全局设置为 false(或 No),则项目引用将不会链接到任何内容.如果它是 true,它将链接进来.

更多:

  • 如果此设置 LinkLibraryDependency 在您的设置中完全缺失,它将默认为 true(来自 Microsoft.MSBuild 文件夹中的 Cpp[.Common].props 文件).
  • 如果您的全局设置中碰巧有值 This is not used这将被解释为 true.
  • 如果你有值False is the new truth!,或者在这个设置中No way,它也会被解释为true 通过构建.
  • 如果 VS2015 GUI 无法解释此处的字符串,则会显示警告:
  • VS2010 GUI 将为所有值显示 Falsefalse 除外,即使这随后被解释为 true 在构建项目时.

更重要的是:

似乎当转换带有 vcproj 文件的旧解决方案时,转换器将采用 slnvcproj 项目的 Linker 选项的值,并为它插入新 vcxproj 的每个 ProjectReference 实际设置 LinkLibraryDependency- 这就是我认为这么长时间以来这是一个死选项的一个原因 - 我们的大多数项目都有可追溯到 VS2005 的转换历史.

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:

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?

解决方案

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 has LinkLibraryDependecies set, then it is in effect meaningless.

However, when adding a new reference, by default (in VS2010 and 2015) the new <ProjectReference> element in the vcxproj 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:

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
  <ItemDefinitionGroup>
    <ClCompile>
...
    </ClCompile>
    <Link>
...
    </Link>
    <ProjectReference>
      <LinkLibraryDependencies>This option is not used by VS 2010!</LinkLibraryDependencies>
    </ProjectReference>
...
  </ItemDefinitionGroup>
</Project>

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 .propsfile), is to set the default value of the Link Library Dependencies Value for each project dependency on the Frameworks 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:

...
  <ItemGroup>
    <ProjectReference Include="..W32DynLib1W32DynLib1.vcxproj">
      <Project>{96be134d-acb5-....-....-....bb6fe4a7}</Project>
    </ProjectReference>
  </ItemGroup>

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 (or No), the project reference won't link in anything. If it's true, it will link in.

What's more:

  • If this setting, LinkLibraryDependency, is completely missing from your settings, it will default to true (from the Microsoft.Cpp[.Common].propsfile in the MSBuild folder).
  • If you happen to have the value This is not used in your global setting, this will be interpreted as true.
  • If you have the value False is the new truth!, or maybe No way in this setting, it will also be interpreted as true by the build.
  • The VS2015 GUI will display a warning if it cannot interpret the string here:
  • The VS2010 GUI will display False for ALL values, except 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 the sln and the value of the vcproj project's Linker option, and actually set the LinkLibraryDependency for each ProjectReference it inserts into the new vcxproj - 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.

这篇关于“链接库依赖"有什么作用?链接器选项实际上在 Visual Studio 2010 - 2015 及更高版本中执行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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