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

2

8

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.

Gambado answered 25/8, 2015 at 22:59 Comment(1)
Does this answer your question? How to add additional libraries to Visual Studio project?Bisexual
I
13

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.

Incapable answered 25/8, 2015 at 23:16 Comment(2)
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?Gambado
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.Incapable
K
-2

go to project add existing item you must then select from the browse screen the .lib file you wish to add. and BINGO it is there!

best wishes david

Katherinkatherina answered 26/1, 2019 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.