如何在Visual Studio 2012中包含库? [英] How to include libraries in Visual Studio 2012?
问题描述
我开始学习C ++几天前,我想获得一些数据,使它更有趣。我发现一个名为Unirest的强大的C ++库,可以帮助我从许多API获取数据,并在实践基本功能后):
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 :)
我不知道如何将库包含到我的项目中。我喜欢一些视频关于如何做,所以我只是创建了 libs
文件夹(像我一直在做PHP编程时)和我复制的库文件。在我包含头文件 UNIRest.h
到我的源中,并将 libs
目录添加到VS + Directories选项<项目属性 - 配置属性 - VC +目录。一切还是OK。但是当我打开头文件 UNIRest.h
时,出现了问题:
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 :(
推荐答案
通常你需要做5件事在您的项目中包含一个库:
Typically you need to do 5 things to include a library in your project:
1)使用声明/接口添加#include语句必要的文件,例如:
1) Add #include statements necessary files with declarations/interfaces, e.g.:
#include "library.h"
添加一个include目录供编译器查看
2) Add an include directory for the compiler to look into
- >配置属性/ VC ++目录/包含目录(点击并编辑,添加新条目)
-> Configuration Properties/VC++ Directories/Include Directories (click and edit, add a new entry)
3)为* .lib文件添加库目录:
3) Add a library directory for *.lib files:
- >项目/ VC ++目录/库目录(点击并编辑,添加新条目)
-> project(on top bar)/properties/Configuration Properties/VC++ Directories/Library Directories (click and edit, add a new entry)
4)链接lib的* .lib文件
4) Link the lib's *.lib files
- >配置属性/链接器/输入/附加依赖关系(例如:library.lib;
-> Configuration Properties/Linker/Input/Additional Dependencies (e.g.: library.lib;
5)放置* .dll文件:
5) Place *.dll files either:
- >在目录中,您将从或打开您的最终可执行文件到Windows / system32
-> in the directory you'll be opening your final executable from or into Windows/system32
这篇关于如何在Visual Studio 2012中包含库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!