简体   繁体   中英

How to include libraries in Visual Studio 2012?

I started with learning C++ a few days ago and I would like to get some data to make it more funny. I found a powerful C++ library called Unirest that can help me to get data from many APIs and after practice the basics :)

I don't know how to include libraries into my project. I fond some videos about how to do it so I just created libs folder (like i always do when I'm programming in PHP) and I copied library files. After I included header file UNIRest.h into my source and added the libs directory into VS+ Directories option in Project Properties - Configuration Properties - VC+ Directories . Everything is still OK. But when I opened the header file UNIRest.h the problem appeared:

#import "UNIHTTPRequest.h"
#import "UNIHTTPRequestWithBody.h"
#import "HttpRequest/UNISimpleRequest.h"
#import "HttpRequest/UNIBodyRequest.h"
#import "HttpResponse/UNIHTTPBinaryResponse.h"
#import "HttpResponse/UNIHTTPJsonResponse.h"
#import "HttpResponse/UNIHTTPStringResponse.h"

All of those macros are underlined and compilation failed with message:

fatal error C1083: Cannot open type library file: 'libs\unirest\unihttprequest.h': Error loading type library/DLL.

Could you please help me? Hope it's not just a stupid question because I tried to make it works whole afternoon :(

Typically you need to do 5 things to include a library in your project:

1) Add #include statements necessary files with declarations/interfaces, eg:

#include "library.h"

2) Add an include directory for the compiler to look into

-> Configuration Properties/VC++ Directories/Include Directories (click and edit, add a new entry)

3) Add a library directory for *.lib files:

-> project(on top bar)/properties/Configuration Properties/VC++ Directories/Library Directories (click and edit, add a new entry)

4) Link the lib's *.lib files

-> Configuration Properties/Linker/Input/Additional Dependencies (eg: library.lib;

5) Place *.dll files either:

-> in the directory you'll be opening your final executable from or into Windows/system32

In code level also, you could add your lib to the project using the compiler directives #pragma .

example:

#pragma comment( lib, "yourLibrary.lib" )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM