How do I include libraries to a project in Visual Studio?

28,698

A library is added in two steps

  1. Adding headers path to the project
  2. Adding .lib reference

In the first step, you must specify in the project where library headers are header. Usually, the path is specified in the project properties -> C++ -> Additional include directories, and them including files with relative paths.

In the second step you must specify in properties->linker the path where libraries (.lib) are located and the name of the library. With this Visual Studio is able to link the project properly.

Share:
28,698
Oscar Vasquez
Author by

Oscar Vasquez

Updated on February 17, 2020

Comments

  • Oscar Vasquez
    Oscar Vasquez over 4 years

    I am a beginner on C++ and trying to learn about including libraries, and I haven't found documentation about it.

    1. What are the ways of including libraries to a C++ project (Visual Studio). How do I implement them and which is the best way?

    2. I was trying to include the SQLite library to a project. I tried to:

      Include the header file in the include folder of the Visual Studio installation folder. It did appear in the External dependencies of my project, so I can do #include <sqlite3.h> without problems, but I don't know where I should put the implementation (a C file) and how to link it (is it in the linker>Input>Additional dependencies?).

    Is it necessary that in order to include a library the file should be a .lib? Because I can't find the .lib for SQLite 3, do I have to include it in the lib folder of my Visual Studio installation?

    Note: I am interested on the management of including a library in general. The SQLite 3 part is only because I took it as an example in order to learn how to add them.

  • Oscar Vasquez
    Oscar Vasquez over 8 years
    Question, one generally doesn't find the .lib file on the internet right? You will most likely have to build it?. And if true, is it because c/c++ is compiled instead of interpreted?
  • Jepessen
    Jepessen over 8 years
    When you use a library in windows you have two files: a .lib that's used by the compiler in order to perform linking, and a .dll that's used by the program when executed. When you take a library you can have or the source code that allows you to build the library yourself, or a packet with the dll, the lib and headers. In order to use a library you need it built, if you build it or if someone else does it for you does not matter by the program that uses that library.