22

I am trying to add static libraries to my project. To add the static library I am following Microsoft's instructions: http://msdn.microsoft.com/en-us/library/ms235627.aspx. My problem is I that am not able to see the dependent library while adding the reference to my project.

In the tutorial mentioned above, they have mentioned that the dependency (ie. static library), should be added to the solution.

Screenshot

SolarBear
  • 4,534
  • 4
  • 37
  • 53
Bhupesh Pant
  • 4,053
  • 5
  • 45
  • 70

2 Answers2

56

The tutorial you have provided refers to a case in which you create your own static library - in this case you may want to add it to your solution and thus make it an integral part of the solution; but I assume you are trying to add external libraries (not created by you, e.g. downloaded from the net) - that is why you got stuck.

On Property Pages, go to C/C++->General->Additional Include Directories and provide the path, where the header file of the library that you want to use is located.

Then go to Linker->General->Additional Library Directories and specify the path, where your .lib file is located.

Finally, go to Linker->Input->Additional Dependencies and add the name of the file containing your library together with its extension (e.g. example_library.lib).

That is all. Now you should be able to use the library. Remember to #include it in your files and use the right mode (release/debug) and the right version for your platform (x64/win32). You may have to repeat the steps given above both for release and debug versions of your app.

KjMag
  • 2,650
  • 16
  • 16
  • 5
    I am exactly following the same steps but still I am getting linking errors. – Bhupesh Pant May 27 '14 at 09:36
  • 3
    If you don't provide the error, maybe some code that causes it as well as the name of the library, it will be hard to help you further. – KjMag May 27 '14 at 13:07
  • I'm a bit confused by all this, I didn't complete the Linker steps but I can still compile and link my project.. (it is a DLL project that uses a static library project I created in the same solution) I did add a reference, it is mentioned here to add a reference ([Walkthrough: Create and use a static library (C++) | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-static-library-cpp?view=msvc-170)) - so what does adding a reference do? – ycomp Jan 06 '23 at 10:08
  • I have followed these instructions in a new C++ project in order to add reference to statically linked (so I thought) copy of assimp-vc143-mt.lib (if it helps this was placed on my machine via vcpkg) . However at run time, I'm asked for the dll version of same. Why might this be? I thought this method of linking would prevent the need for the dll at runtime. – Rory Becker Feb 17 '23 at 11:41
-2

I am just extending the answer given by KjMag. It's a great answer, except that it misses the part where we tell the linker which external libraries to add.
In Visual Studio, go to Property Pages >> Linker >> Input >> Additional Dependencies. Here we can add the required libraries.