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

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

  1. https://curl.haxx.se/download.html 下载 curl 压缩包(最新验证的是:https://curl.haxx.se/download/curl-7.70.0.zip)
  2. 将下载的包解压到您选择的文件夹(例如 C:curl)
  3. 打开 Developer Command Prompt for VS 2017(请参阅 Windows 开始菜单或 %PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools) 和 cdC:curlwinbuild
  4. 运行 nmake/f Makefile.vc mode=static.这会将 curl 作为静态库构建到 C:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssl
  5. 在 Visual Studio 中创建一个新项目(例如 Windows 控制台应用程序)
  6. 在项目 Properties ->VC++ 目录 ->包含目录 add C:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winsslinclude
  7. 在项目 Properties ->VC++ 目录 ->库目录在那里添加C:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssllib
  8. 在项目 Properties ->链接器 ->输入 ->附加依赖 添加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.70.0.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%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools) and cd to C:curlwinbuild
  4. Run nmake /f Makefile.vc mode=static. This will build curl as a static library into C:curluildslibcurl-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:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winsslinclude
  7. In Project Properties -> VC++ Directories -> Library Directories add C:curluildslibcurl-vc-x86-release-static-ipv6-sspi-winssllib 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 <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:

  1. https://github.com/microsoft/vcpkg/releases (例如 https://github.com/microsoft/vcpkg/archive/2019.09.zip) 并将其解压缩到您选择的文件夹(例如 C:vcpkg)
  2. 打开 Developer Command Prompt for VS 2017(请参阅 Windows 开始菜单或 %PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual Studio Tools>) 和 cdC:vcpkg
  3. 运行bootstrap-vcpkg.bat
  4. 运行vcpkg.exe集成安装
  5. 运行vcpkg.exe install curl
  6. 在 Visual Studio 中创建一个新的 C++ 项目,然后就可以开始了 - 用上面的例子试试.无需修改项目设置.
  1. 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)
  2. Open Developer Command Prompt for VS 2017 (see Windows Start menu or %PROGRAMDATA%MicrosoftWindowsStart MenuProgramsVisual Studio 2017Visual 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天全站免登陆