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

I am a beginner on C++ and trying to learn about including libraries, and I haven't found documentation about it.
What are the ways of including libraries to a C++ project (Visual Studio). How do I implement them and which is the best way?
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.

A library is added in two steps
Adding headers path to the project
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.

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

Related

How can I add/import chibios library for embedded project in visual studio?

I want to use ch.h file from chibios in my project. The embedded project is created and is using HAL drivers for stm32. I want to find a way to add or import chibios library to the current project.
My question is that
how can I add these embedded libraries with lots of dependencies by visualGDB in visual studio?
Do I need to create .lib files of chibios?
What are the differences between C/C++ paths and linker paths?
Adding .a and .h files is enough or do I have to look for other files?
There are 3 ways that I followed and it wasn't successful.
I followed the link to add the paths.
The files that added to projects are libch.a and ch.h. It is called other header files inside ch.h. Then, I added the other header paths to C/C++ "additional include directories" too. After I added the third header file, I got the error "redefinition".
The second way, I wanted to use vcpkg, a library manager. But the chibios library wasn't available in vcpkg.
One another way is to add libraries in standard libraries without adding any paths. But how can I find standard libraries? If the location is in the compiler (gcc-arm-none-eabi), the chibios package was added, but it still wasn't detected in visual studio.
I really appreciate it if you know any tutorials or ways to add chibios in the visual studio

whats means "Link executables with xxx.lib"

I have one guide integrating software files to my program on c++. Steps are:
-Add /Resources/xxx-io/include/ directory to your project include directories settings
-Add /Resources/xxx-io/lib/ directory to your project library directories settings
-Include xxx.h in your software code
Link executables with xxx.lib
What dose the last one mean? I'm building simple win console program with visual studio 2015 c++ that communicates with software. I have linked the lib and includes and included header, but that last one is mystery.
To say simply, it means that you should go to Project properities -> Linker -> Input and add there library, to which you want your executable to link to.
If you want to learn what does it actually mean, read some articles on how .libs work. To say shortly, .lib library is compiled code, that is inserted into your program.

Build QtDropbox in C++ (Cannot find QLocale)

I am trying to build QtDropbox to use in a project of my own in visual studio. QtDropbox uses Qt of course and I included it into the project (as you can see on the image).
My problem is that it cannot find #include <QLocale>. So what dependency did I forgot?
In order to let your compiler find the mentioned include file you have to extend the list of Include Directories in your Visual Studio project's configuration. The mentioned file can be found in QtCore sub directory of Qt include files, so you simply need to add C:\Qt\5.4\msvc2013_64\include\QtCore path to the list too.

How to add lib files and headers to a C++ Project

I have been using libcurl in a C++ project.
I have added the libcurl Include and Library directory's to the VC++ Directories and added the .lib file to the Linkers Input Additional Dependencies.
Everything works fine but when I check in my code (TFS) and somebody gets it on another machine they cannot build etc due to not having libcurl installed on their machine or installed in different paths etc.
How do I add all the necessary files to my C++ Solution so that anyone getting the project from source control can build and link without error.
Thanks
The solution I went with was too add the library file to a folder within my solution, then add
$(SolutionDir)libs\curllib.lib
To the Additional Dependencies within Linker->Input
You can not add the library to the solution. you should distribute the library along the source code. Place it in a subdirectory of the project so that it goes along the whole project source. Then configure the path in Additional Library Dependencies. That way the people should be able to link appropriately when building from source.

DLL References in Visual C++

I have had C++ experience but not MSVC.
What I am trying to do is incorporate a .dll from an open source project into my project. The code is available and I have built it. I have the .dll as well as the .lib which as I understand it is required for C++ projects.
Now unfortunately there is no simple "Add Reference", drop my .dll into an include directory and add that to my solution. I have edited the project property pages, the C/C++ Additional Include Directories option as well as adding the .lib as an additional linker dependency. I have created an include directory for the dll and lib inside my solution tree.
My problem is when I try to include the header files from the documentation, VS output spits out error messages. Now I realize that I am using the dll/lib combo and that the .h files are not present in my solution so how do I add the proper includes? I am using QT toolkit also which is working but how I add the other header / dll from the open source library eludes me.
Can someone please point me in the right direction.
You need to do a couple of things to use the library:
Make sure that you have both the *.lib and the *.dll from the library you want to use. If you don't have the *.lib, skip #2
Put a reference to the *.lib in the project. Right click the project name in the Solution Explorer and then select Configuration Properties->Linker->Input and put the name of the lib in the Additional Dependencies property.
You have to make sure that VS can find the lib you just added so you have to go to the Tools menu and select Options... Then under Projects and Solutions select VC++ Directories,edit Library Directory option. From within here you can set the directory that contains your new lib by selecting the 'Library Files' in the 'Show Directories For:' drop down box. Just add the path to your lib file in the list of directories. If you dont have a lib you can omit this, but while your here you will also need to set the directory which contains your header files as well under the 'Include Files'. Do it the same way you added the lib.
After doing this you should be good to go and can use your library. If you dont have a lib file you can still use the dll by importing it yourself. During your applications startup you can explicitly load the dll by calling LoadLibrary (see: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx for more info)
Cheers!
EDIT
Remember to use #include < Foo.h > as opposed to #include "foo.h". The former searches the include path. The latter uses the local project files.
The additional include directories are relative to the project dir. This is normally the dir where your project file, *.vcproj, is located. I guess that in your case you have to add just "include" to your include and library directories.
If you want to be sure what your project dir is, you can check the value of the $(ProjectDir) macro. To do that go to "C/C++ -> Additional Include Directories", press the "..." button and in the pop-up dialog press "Macros>>".
You mention adding the additional include directory (C/C++|General) and additional lib dependency (Linker|Input), but have you also added the additional library directory (Linker|General)?
Including a sample error message might also help people answer the question since it's not even clear if the error is during compilation or linking.