如何正确安装libcurl以在Visual Studio 2017中使用? [英] How do you properly install libcurl for use in visual studio 2017?

查看:673
本文介绍了如何正确安装libcurl以在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:

  1. https://curl.haxx.se/download.html(最新验证为: https://curl.haxx.se/download/curl-7.69.1.zip )
  2. 将下载的软件包提取到您选择的文件夹中(例如C:\curl\)
  3. 打开Developer Command Prompt for VS 2017(请参阅Windows开始"菜单或%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\),然后将cd切换到C:\curl\winbuild\
  4. 运行nmake /f Makefile.vc mode=static.这会将curl作为静态库构建到C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\
  5. 在Visual Studio中创建一个新项目(例如Windows Console Application)
  6. 在项目Properties -> VC++ Directories -> Include Directories中添加C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include\
  7. 在项目Properties -> VC++ Directories -> Library Directories中在其中添加C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\
  8. 在项目Properties -> Linker -> Input -> Additional Dependencies中添加libcurl_a.libWs2_32.libCrypt32.libWldap32.libNormaliz.lib
  9. 尝试构建示例程序:
  1. Download curl zip package from https://curl.haxx.se/download.html (latest verified is: https://curl.haxx.se/download/curl-7.69.1.zip)
  2. Extract downloaded package to a folder of your choice (e.g. C:\curl\)
  3. Open Developer Command Prompt for VS 2017 (see Windows Start menu or %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\) and cd to C:\curl\winbuild\
  4. Run nmake /f Makefile.vc mode=static. This will build curl as a static library into C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\
  5. Create a new project in Visual Studio (e.g. a Windows Console Application)
  6. In Project Properties -> VC++ Directories -> Include Directories add C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include\
  7. In Project Properties -> VC++ Directories -> Library Directories add C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\ there
  8. In Project Properties -> Linker -> Input -> Additional Dependencies add libcurl_a.lib, Ws2_32.lib, Crypt32.lib, Wldap32.lib and Normaliz.lib
  9. 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:

  1. > https://github.com/microsoft/vcpkg/archive/2019.08.zip 并将其解压缩到您选择的文件夹中(例如C:\ vcpkg \)
  2. 打开Developer Command Prompt for VS 2017(请参阅Windows开始"菜单或%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\),然后将cd移至C:\vcpkg\
  3. 运行bootstrap-vcpkg.bat
  4. 运行vcpkg.exe integrate install
  5. 运行vcpkg.exe install curl
  6. 在Visual Studio中创建一个新的C ++项目,您就可以开始使用-结合上面的示例进行尝试.无需修改项目设置.
  1. 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\)
  2. Open Developer Command Prompt for VS 2017 (see Windows Start menu or %PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\) and cd to C:\vcpkg\
  3. Run bootstrap-vcpkg.bat
  4. Run vcpkg.exe integrate install
  5. Run vcpkg.exe install curl
  6. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆