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

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

问题描述

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

Properties -> Linker -> General : Link Library Dependencies = Yes

设置

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


侧面注意:Microsoft更改了 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是否打破了"Project Dependencies" ;在C ++项目之间?
  • > Visual Studio 2010无法自动链接应该是依赖项的项目中的静态库
  • ,尤其是在这里(紧随其后的是问题)

    Microsoft确认Linker Option不能满足世界其他地区人们的预期,并在其中添加了以下说明:

    感谢您报告此反馈.您遇到的问题是 通过设计. 链接库依赖关系"是仅指示 是否将库作为输入传递给链接器.确实 无法自动找到依赖项.作为客户,您将必须 根据您的建议手动定义容灾度.

    任何人都可以解释这是什么意思,或者甚至更重要的是:链接库依赖"链接器选项在Visual Studio 2010中实际上起什么作用?

    什么是实际上没有链接的链接器输入"?

    解决方案

    2017重新运行.是的.

    TL; DR

    此选项为每个项目参考上的实际Link Library Dependecies设置默认值 (a).如果每个项目引用都设置了LinkLibraryDependecies,则它实际上是没有意义的.

    但是,当添加新引用时,默认情况下(在VS2010和2015中),vcxproj文件中的新<ProjectReference>元素没有 设置,因此此选项是相关的因为它为所有新添加的引用提供了默认值,只要它们的值没有被修改即可.

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

    详细信息

    Hans指出,看来 在VS2010中不做任何事情这样的.但是,这并不意味着VS/MSBuild实际上并未使用它.

    关键是如何将此选项插入到vcxprj文件中,以及如何将默认值用于msbuild文件中的<ProjectReference>设置.

    如上所示,在链接器"对话框上的设置被插入为:

    <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文件的文件)中实际执行的操作设置Link Library Dependencies值的默认值Frameworks and References部分上的每个项目依赖项->

    -或在VS2015参考的子树中-

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

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

    您会发现<LinkLibraryDependecies>true|false</..>子元素在此处丢失:这意味着您实际上将使用全局"设置来设置默认值.

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

    更多:

    • 如果您的设置中完全缺少此设置LinkLibraryDependency,则它将默认为 true (来自MSBuild文件夹中的Microsoft.Cpp[.Common].props文件).
    • 如果您在全局设置中碰巧具有值This is not used,则这将被解释为true .
    • 如果您在此设置中将值设置为False is the new truth!No way,则该版本还将解释为true .
    • 如果VS2015 GUI无法在此处解释字符串,则会显示警告:
    • 对于VS2010 GUI,false以外的所有值都将显示 False ,即使在构建项目.

    更多:

    似乎,当使用vcproj文件转换旧解决方案时,转换器将采用sln中指定的旧依赖关系以及vcproj项目的Linker选项的值,并实际上为插入到新vcxproj中的每个ProjectReference设置LinkLibraryDependency-这就是我认为这很久以来一直是一个无效选项的原因-我们的大多数项目都有可以追溯到VS2005的转换历史. /p>

    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="..\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:
    • 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天全站免登陆