“链接库依赖关系”是什么意思?链接器选项实际上在 Visual Studio 2010 - 2015 及更高版本中起作用吗?

发布于 2024-12-09 00:57:25 字数 2259 浏览 0 评论 0原文

到 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

我对此很满意。 不是这个问题的意思。

(这里有一个解释:灵活的项目到项目引用。)


但是仍然可以定义项目对解决方案级别的依赖关系常规链接器选项也仍然在那里。然而它不起作用。请参阅:

,特别是参见此处(实际问题如下)

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:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

王权女流氓 2024-12-16 00:57:25

您必须为设置提供正确的值以使其清晰:

在此处输入图像描述

You have to give the setting the proper value to bring clarity:

enter image description here

动次打次papapa 2024-12-16 00:57:25

2017年重新运行。耶。

TL;DR

此选项为每个项目引用上的实际链接库依赖项设置默认值(a)。如果每个项目引用都设置了 LinkLibraryDependecies,那么它实际上毫无意义。

但是,添加新引用时,默认情况下(在 VS2010 和 2015 中)vcxproj 文件中的新 元素不会已设置设置,因此此选项是相关的,因为它为所有新添加的引用提供默认值,只要它们的值未被修改。

(a):对于所有配置(调试/发布)和平台(Win32/x64),确实应该是相同的,否则事情会变得非常复杂。

血淋淋的细节

Hans指出似乎在VS2010中没有做任何事情 。然而,这并不意味着 VS/MSBuild 实际上不使用它。

关键在于如何将此选项插入到 vcxprj 文件中,以及默认值如何在 msbuild 文件中的 设置中发挥作用。

如上所示的链接器对话框中的设置插入为:

未实际实现

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

虽然它似乎以某种方式与Link选项组合在一起,但事实就是如此来迷惑你。

在给定的 vcxproj 文件(或来自 .props 文件)中,它的实际作用设置默认值VS2010 VC 设置对话框中的框架和引用部分中每个项目依赖项的链接库依赖项 --

参考文献中的链接库2010

——或者在 VS2015 参考的子树中——

References 2015中的链接库">

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

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

您会注意到此处缺少 true|false 子元素:这意味着您的“全局”设置实际上将用于设置默认值。

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

此外:

  • 如果您的设置中完全缺少此设置 LinkLibraryDependency它将默认为 true (来自 MSBuild 文件夹中的 Microsoft.Cpp[.Common].props 文件)。
  • 如果您的全局设置中碰巧有值 This is notused这将被解释为 true
  • 如果您的值是False is the new true!,或者在此设置中No way,它也会被解释为true建造。
  • 如果 VS2015 GUI 无法解释此处的字符串,则会显示警告: 字符串值 'False 是新的事实!'无法转换为布尔类型的任何值。
  • VS2010 GUI 将为所有值显示 Falsefalse 除外,即使在构建项目时这被解释为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 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:

Not actually implemented

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

Link Lib in the References 2010

-- or in the subtree of the VS2015 References --

Link Lib in the References 2015

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="..\W32DynLib1\W32DynLib1.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: String value 'False is the new truth!' cannot be translated to any value from type Boolean.
  • 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.

德意的啸 2024-12-16 00:57:25

这里的事情是你必须去,项目属性 - >共同属性->框架和参考,然后向您的项目添加新参考。那么只有它才能在 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

纵山崖 2024-12-16 00:57:25

这必须在 Properties / Common / Frameworks and References 中设置。

或者,您可以在 vcxproj 文件中添加类似下面的内容,当然使用您引用的实际项目及其 uuid项目。

<ItemGroup>
    <ProjectReference Include="..\Cpp\Cpp.vcxproj">
        <Project>{c58574bf-9dd8-4cf8-b5b6-6551f2f3eece}</Project>
    </ProjectReference>
</ItemGroup>

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.

<ItemGroup>
    <ProjectReference Include="..\Cpp\Cpp.vcxproj">
        <Project>{c58574bf-9dd8-4cf8-b5b6-6551f2f3eece}</Project>
    </ProjectReference>
</ItemGroup>
っ〆星空下的拥抱 2024-12-16 00:57:25

看来您还必须

<IgnoreImportLibrary>false</IgnoreImportLibrary>

在 REFERENCED 项目中进行设置。

It seems like you also have to set

<IgnoreImportLibrary>false</IgnoreImportLibrary>

in the REFERENCED project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文