Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 462
Oscar Vasquez Avatar asked Aug 25 '15 22:08

Oscar Vasquez


People also ask

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

For adding libraries, this is very simple (if that's what you mean) Project -> properties -> configure properties -> Linker -> Input -> additional libraries. Go stand on one of the libraries in there and press enter.

How do I reference a library in Visual Studio?

A reference is essentially an entry in a project file that contains the information that Visual Studio needs to locate the component or the service. To add a reference, right-click on the References or Dependencies node in Solution Explorer and choose Add Project Reference.


1 Answers

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.

like image 137
Jepessen Avatar answered Sep 22 '22 15:09

Jepessen