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

Oscar Vasquez picture Oscar Vasquez · Aug 26, 2015 · Viewed 24.7k times · Source

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.

Answer

Jepessen picture Jepessen · Aug 26, 2015

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.