如何正确安装 libcurl 以在 Visual Studio 2017 中使用? [英] How do you properly install libcurl for use in visual studio 2017?
问题描述
我刚开始使用 C++,无法弄清楚如何添加库,尤其是 libcurl.我尝试了一堆教程,但大多数是针对 2013/10 或不起作用的.任何人都可以解释(最好用标准/非技术英语)我如何添加库?我已经尝试在程序的包含部分和附加依赖项菜单中添加它.
I am just starting out in c++ and cannot figure out how to add libraries, in particular libcurl. I tried a bunch of tutorials but most were for 2013/10 or didn't work. Can anyone please explain (Preferably in standard/non technical English) how I can add the library? I have already tried adding it in the include section of the program and in the additional dependencies menu.
请注意,这是我大约 3 天前提出的几乎相同问题的重新发布,但我没有收到任何回复.不知道是不是因为它很容易,我应该自己弄清楚,或者它是否只是被淹没在大量问题中,或者其他一些原因.无论如何,很抱歉重新发布.
Note this is a re-post I asked virtually the same question around 3 days ago to which I received no replies. Not sure if that is because its very easy and I should have figured it out my self, or if it just got buried in a flood of questions, or some other reason. In any case sorry for the re-post.
推荐答案
以下是我如何让 curl 在 Visual Studio 2017 15.9.14 中工作:
Here's how I've got curl to work with Visual Studio 2017 15.9.14:
- 从 https://curl.haxx.se/download.html 下载 curl 压缩包(最新验证的是:https://curl.haxx.se/download/curl-7.70.0.zip)
- 将下载的包解压到您选择的文件夹(例如
C:curl
) - 打开
Developer Command Prompt for VS 2017
(请参阅 Windows 开始菜单或%PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools
) 和cd
到C:curlwinbuild
- 运行
nmake/f Makefile.vc mode=static
.这会将 curl 作为静态库构建到C:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssl
- 在 Visual Studio 中创建一个新项目(例如
Windows 控制台应用程序
) - 在项目
Properties ->VC++ 目录 ->包含目录
addC:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winsslinclude
- 在项目
Properties ->VC++ 目录 ->库目录
在那里添加C:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssllib
- 在项目
Properties ->链接器 ->输入 ->附加依赖
添加libcurl_a.lib
、Ws2_32.lib
、Crypt32.lib
、Wldap32.lib
和Normaliz.lib
- 尝试构建一个示例程序:
- Download curl zip package from https://curl.haxx.se/download.html (latest verified is: https://curl.haxx.se/download/curl-7.70.0.zip)
- Extract downloaded package to a folder of your choice (e.g.
C:curl
) - Open
Developer Command Prompt for VS 2017
(see Windows Start menu or%PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools
) andcd
toC:curlwinbuild
- Run
nmake /f Makefile.vc mode=static
. This will build curl as a static library intoC:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssl
- Create a new project in Visual Studio (e.g. a
Windows Console Application
) - In Project
Properties -> VC++ Directories -> Include Directories
addC:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winsslinclude
- In Project
Properties -> VC++ Directories -> Library Directories
addC:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssllib
there - In Project
Properties -> Linker -> Input -> Additional Dependencies
addlibcurl_a.lib
,Ws2_32.lib
,Crypt32.lib
,Wldap32.lib
andNormaliz.lib
- Try to build a sample program:
#define CURL_STATICLIB
#include <curlcurl.h>
int main()
{
CURL *curl;
curl = curl_easy_init();
curl_easy_cleanup(curl);
return 0;
}
或者你可以使用 vcpkg 来安装 curl:
Alternatively you can use vcpkg to install curl:
- 从 https://github.com/microsoft/vcpkg/releases (例如 https://github.com/microsoft/vcpkg/archive/2019.09.zip) 并将其解压缩到您选择的文件夹(例如 C:vcpkg)
- 打开
Developer Command Prompt for VS 2017
(请参阅 Windows 开始菜单或%PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools
>) 和cd
到C:vcpkg
- 运行
bootstrap-vcpkg.bat
- 运行
vcpkg.exe集成安装
- 运行
vcpkg.exe install curl
- 在 Visual Studio 中创建一个新的 C++ 项目,然后就可以开始了 - 用上面的例子试试.无需修改项目设置.
- Get latest vcpkg zip file from https://github.com/microsoft/vcpkg/releases (e.g. https://github.com/microsoft/vcpkg/archive/2019.09.zip) and extract it to a folder of your choice (e.g. C:vcpkg)
- Open
Developer Command Prompt for VS 2017
(see Windows Start menu or%PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools
) andcd
toC:vcpkg
- Run
bootstrap-vcpkg.bat
- Run
vcpkg.exe integrate install
- Run
vcpkg.exe install curl
- Create a new C++ project in Visual Studio and you're ready to go - try it with the example above. There's no need to modify project settings.
这篇关于如何正确安装 libcurl 以在 Visual Studio 2017 中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!