59
  • Create a new solution with a C++ console command-line project
  • Create a new project, a C++ static library
  • Make the command-line project depend on the library
  • Make sure "Link Library Dependencies" is turned on in Configuration => Linker => General (it is by default)
  • Visual Studio will still not link the library.

How can I fix this? It worked in Visual Studio 2008.

4 Answers 4

83

This still works, but was changed in VS 2010:

"With VS2010, we stopped supporting project dependencies defining implicit references and we also introduced a new way of defining project dependencies at the project level. Since a project reference and a project dependency are close concepts, both applying to a project, it made sense to have them represented together, in a consistent way, in the project file. As you will see in the snippets below, the only difference between a project reference definition and a project dependency definition consists in metadata that defines the output assembly inclusion/exclusion into/from the main project link command line. Although we did not remove the “Project Dependencies” dialog, we recommend defining new project dependencies via the “Framework and References” dialog. You need to set the “Reference Assembly Output” property in the property page UI to false for a project dependency and to true for a project reference."

Just right-click on the console project, select "Properties->Common Properties->Framework and References->Add New Reference" and add the static library project; also check that "Link Library Dependencies" is True on the right hand side. Seems to work for debug and release builds. You learn something new every day. ;)

6
  • 4
    You need to add projects to the current solution? Whats the point of having static libraries then? May 30, 2011 at 12:15
  • 5
    @UtkarshSinha You don't "need" to add the static library project to the solution, but if it's not part of the solution, Visual Studio can't build it. If you have a pre-built static library that is not part of the solution, this entire question does not apply to you.
    – Qwertie
    May 15, 2012 at 22:51
  • 1
    I'd say "M$ makes sure we need to learn something new every day" >:) Oct 11, 2015 at 23:22
  • 4
    For future spelunkers: this has been changed post-VS2010. Right-click on the "References" node in the project within the Solution Explorer and add the dependent project. I suppose if you have an out-of-solution project you will have to add the .lib manually via Properties->Linker->Input or use a shared project.
    – user1531971
    Jan 21, 2016 at 15:02
  • 1
    It is worth noting that for MSVC 14 (2015) one looks under project's "Add->Reference..." and then clicking on the needed dependencies
    – YePhIcK
    Jul 19, 2017 at 3:11
25

They changed the UI for adding C++ project dependencies in VS2010, but oddly enough, without removing the old UI, or in any way indicating that it no longer works.

To create the dependency in VS2010, you need to use "Add New Reference" (can be found in project properties), and maybe also in the project's right-click menu (don't have VS here to check)

The old "Project Dependencies" dialog is basically broken now.

4
  • 4
    Also, the dialog says something about .Net frameworks, even for pure C++ projects. Microsoft clearly hasn't done even basic UI testing on solutions with multiple projects. It's really giving off the impression that Visual Studio is only intended for Hello, World sized projects.
    – MSalters
    Oct 14, 2013 at 11:32
  • 1
    The old UI used to do two things, and these have been seperated. The old UI still does compile dependency ordering, the project properties now handles linking. Just because A needs to be compiled before B doesn't mean B should link with A. Mar 31, 2015 at 18:40
  • 1
    VS 2017 and IT IS STILL BROKEN!@#$!@#$!@#$ but not removed. JFC. >:(
    – Mordachai
    Dec 1, 2017 at 21:01
  • 1
    @Mordachai it's still needed for project order Mar 1, 2018 at 17:25
8

For MSVC 14 (2015 version) right-click on the project, then "Add->Reference..." and check all the needed dependencies.

Yes, it has changed somewhere between 2010 and 2015 versions. Fun!

And if you are looking to link a project that has resources in it - you need to specify the .res file directly in the list of linker input dependencies (project's properties dialog box) as it doesn't get picked up by the above configuration.

UPDATE

Still the same (new) behavior in MSVC 2017

1
  • 4
    Just letting you all know that this also works for MSVC 2017. Feb 21, 2018 at 8:40
3

I believe the old UI (dependencies) affects build order for Visual Studio, when building from within the IDE, for info. The new project configuration system embeds the references in each project file so that you can build from outside the IDE (whereas in previous versions, you could not, because you would not get automatic linking for dependencies, since dependencies were only done at the solution level).

There are also some issues with more complex projects in the new system; specifically, all resulting binary projects need to have explicit references to every dependent library to build correctly, whereas previously they could be effectively inherited from other dependent libraries. Same underlying cause, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.