What does the "Link Library Dependency" linker option actually do in Visual Studio 2010 - 2015 and upwards?

Visual Studio-2010Visual C++LinkerDependenciesProjects and-Solutions

Visual Studio-2010 Problem Overview


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?

Visual Studio-2010 Solutions


Solution 1 - Visual Studio-2010

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

enter image description here

Solution 2 - Visual Studio-2010

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.

Solution 3 - Visual Studio-2010

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

Solution 4 - Visual Studio-2010

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>

Solution 5 - Visual Studio-2010

It seems like you also have to set

<IgnoreImportLibrary>false</IgnoreImportLibrary>

in the REFERENCED project.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartin BaView Question on Stackoverflow
Solution 1 - Visual Studio-2010Hans PassantView Answer on Stackoverflow
Solution 2 - Visual Studio-2010Martin BaView Answer on Stackoverflow
Solution 3 - Visual Studio-2010user1832522View Answer on Stackoverflow
Solution 4 - Visual Studio-2010aepurnietView Answer on Stackoverflow
Solution 5 - Visual Studio-2010Andras NagyView Answer on Stackoverflow