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

2

14

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?

Scold answered 7/9, 2010 at 23:21 Comment(0)
H
20

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

Hadria answered 15/5, 2013 at 10:50 Comment(2)
When I try this, I can successfully compile the program, but when I try to run it an alert dialog appears with the error message The program can't start because TheLibrary.dll is missing from your computer. Try reinstalling the program to fix this problem.. Any idea why it wants the dll file at run time? Because that one shouldn't be needed if one uses the lib file at compile time, right?Shiftless
Hmm... It was a problem with my library. It was created as a shared library, and not a static library. When I changed it it started to work. But why did the shared library produce a lib file?Shiftless
U
2

Project->Properties->Configuration Properties->Linker->Command Line. Spell your_lib_name.lib there to link with it. Alternatively - use Linker->Input->Additional dependencies option (it does the same as directly specifying libs in command line). As for .h - just #include it. You might want to add include path for it, though.

Ununa answered 6/11, 2011 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.