Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an external static library to a Visual C++ 2010 Express project

I can't believe I'm having such a hard time figuring out how to do something so simple. I have an external library (including a .lib and .h file) that I want to add to my project. From what I've read I need to go Project>Properties>Framework and references>Add new References and add it there.

However, this window is blank. There is a Project name and Project Directory column but there is nothing there and no 'browse' button to find my library. I tried going to VC++ directory and adding the path to the .lib file to the libraries path but it didn't help.

What am I missing?

like image 785
Sarevok Avatar asked Sep 07 '10 23:09

Sarevok


People also ask

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

To create a static library project in Visual StudioOn the menu bar, choose File > New > Project to open the Create a New Project dialog. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.

How do I add external dependencies to a project 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 ).

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.


1 Answers

If you have external files you cannot use the reference tab because it just references project in the current solution, so you have to to it manually.

To reach your goal you just need to follow the following step

  1. Left clik on your Project and select Properties
  2. In the Properties Dialog go to Configuration Properties (in the next step we will always assumet to be under Configuration Properties)
  3. In C/C++ -> General edit the Additional Include Directories property adding the path to your header file (.h file)
  4. In Linker -> General edit the Additional Library Directories property adding the path to your static library (.lib file)
  5. In Linker -> Input edit the Additional Dependencies property adding the name of your Library (name of your .lib file)

Now you can easily use the function in your static library just including the .h header in your code file ( #include "myLib.h" )

like image 198
il_guru Avatar answered Oct 20 '22 09:10

il_guru