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:
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?
The Microsoft Visual C++ suite includes a LINK. EXE program that works primarily with object files as input, to produce an executable as output, but also is capable of much other work concerning these and related files. The different kinds of work are separated by having LINK.
Just right click on your project and select properties. There you will get another set of options under 'Configuration Properties' . Go to C/C++ and under that -> General -> Additional Include Directories ( where all the header files of third party is there ).
You have to give the setting the proper value to bring clarity:
2017 Re-Run. Yay.
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.
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 .props
file), 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:
LinkLibraryDependency
, is completely missing from your settings, it will default to true (from the Microsoft.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 maybe No 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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With