Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to

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

like image 636
Thomas Bonini Avatar asked Sep 25 '10 21:09

Thomas Bonini


People also ask

How do I add a static library to Visual Studio project?

To create a static library project in Visual Studio 2015On the menu bar, choose File > New > Project. In the New Project dialog box, select Installed > Templates > Visual C++ > Win32. In the center pane, select Win32 Console Application.

Do static libraries have dependencies?

If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.

What is the difference between dependencies and references in Visual Studio?

They are basically no different, they are used to store and manage references. Just as Lex said, the Dependencies is a better way to represent different types of references, we can clearly know where the reference comes from, SDK, nuget, etc. so that we can manage our references more efficiently.


2 Answers

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. ;)

like image 109
Sean Fausett Avatar answered Oct 25 '22 08:10

Sean Fausett


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.

like image 26
jalf Avatar answered Oct 25 '22 08:10

jalf