如何在 Visual Studio 2012 中包含库?

How to include libraries in Visual Studio 2012?(如何在 Visual Studio 2012 中包含库?)

本文介绍了如何在 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 目录添加到 项目属性 - 配置属性 - VC+ 目录 中的 VS+ 目录选项后.一切都还好.但是当我打开头文件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: 'libsunirestunihttprequest.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"

2) 添加一个包含目录供编译器查看

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 中包含库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Visual Studio 2012 中包含库?

基础教程推荐