如何正确安装libcurl以在Visual Studio 2017中使用? [英] How do you properly install libcurl for use in visual studio 2017?
问题描述
我只是从C ++开始,无法弄清楚如何添加库,尤其是libcurl.我尝试了一堆教程,但是大多数教程是针对2013/10的,或者没有用.谁能解释(最好用标准/非技术英语)我如何添加库?我已经尝试在程序的include部分和其他依赖项菜单中添加它.
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.
推荐答案
这是我如何使用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(最新验证为: https://curl.haxx.se/download/curl-7.69.1.zip )
- 将下载的软件包提取到您选择的文件夹中(例如
C:\curl\
) - 打开
Developer Command Prompt for VS 2017
(请参阅Windows开始"菜单或%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\
),然后将cd
切换到C:\curl\winbuild\
- 运行
nmake /f Makefile.vc mode=static
.这会将curl作为静态库构建到C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\
中
- 在Visual Studio中创建一个新项目(例如
Windows Console Application
) - 在项目
Properties -> VC++ Directories -> Include Directories
中添加C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include\
- 在项目
Properties -> VC++ Directories -> Library Directories
中在其中添加C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\
- 在项目
Properties -> Linker -> Input -> Additional Dependencies
中添加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.69.1.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%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\
) andcd
toC:\curl\winbuild\
- Run
nmake /f Makefile.vc mode=static
. This will build curl as a static library intoC:\curl\builds\libcurl-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:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include\
- In Project
Properties -> VC++ Directories -> Library Directories
addC:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\
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 <curl\curl.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/archive/2019.08.zip 并将其解压缩到您选择的文件夹中(例如C:\ vcpkg \)
- 打开
Developer Command Prompt for VS 2017
(请参阅Windows开始"菜单或%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\
),然后将cd
移至C:\vcpkg\
- 运行
bootstrap-vcpkg.bat
- 运行
vcpkg.exe integrate install
- 运行
vcpkg.exe install curl
- 在Visual Studio中创建一个新的C ++项目,您就可以开始使用-结合上面的示例进行尝试.无需修改项目设置.
- Get vcpkg from https://github.com/microsoft/vcpkg/archive/2019.08.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%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual 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屋!