Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add static libraries to a Visual studio project

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

like image 937
Bhupesh Pant Avatar asked May 27 '14 06:05

Bhupesh Pant


People also ask

Where do I put my static library?

Static libraries belong next to their corresponding dynamic libraries, and in accordance with the FHS. Keep in mind that static libraries are usually only needed to build software, not run it.

How do I add external dependencies in Visual Studio?

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

How do I reference a library in Visual Studio?

To add a reference to a type library in Visual StudioSelect the type library from the list, or browse for the . tlb file. Choose OK. In Solution Explorer, open the shortcut menu for the reference you just added, and then choose Properties.


2 Answers

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.

like image 81
KjMag Avatar answered Oct 19 '22 09:10

KjMag


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.

like image 43
debashish.ghosh Avatar answered Oct 19 '22 09:10

debashish.ghosh