*按照以下步骤,我使CURL在64位计算机上的VS 2017中工作(请参阅下面的原始问题):
* I got CURL working in VS 2017 on a 64 bit machine following these steps (see below for original problem):
首先安装vcpkg:
然后使用vcpkg和Visual Studios 2017命令提示符安装cURL:
Then use vcpkg and Visual Studios 2017 command prompt to install cURL:
运行:vcpkg install curl[*]:x64-windows(请注意,下载和运行此过程可能需要大约半小时,请放心,如果它看起来卡在"了部件上).
Run: vcpkg install curl[*]:x64-windows (note this can take around a half hour to download and run, don't worry if it looks like it is "stuck" at parts).
* Edit:以前,我的指令说要运行vcpkg install curl:x64-windows,但我是根据@ i7clock的要求在[*]上添加的,以启用sftp和scp协议.
* previously my instructions said to run vcpkg install curl:x64-windows but I added on the [*] at the behest of @i7clock to enable sftp and scp protocols.
在此步骤之后,您应检查并确保正确安装了curl.为此,您应该在VS 2017中创建一个新项目,并尝试包含#include curl/curl.h而不添加任何其他包含目录.如果您不能执行此操作,则说明curl的安装有问题.您应该删除curl(甚至可能是vcpkg文件夹并进行全新安装),直到可以包含curl/curl.h.
After this step, you should check to make sure that curl installed correctly. To do this you should create a new project in VS 2017 and try and include #include curl/curl.h without adding any additional include directories. If you cannot do this then something went wrong with your install of curl. You should remove curl (and perhaps even the vcpkg folder and do a clean install) until you can include curl/curl.h.
*重要说明:仅当您在x64中使用x64调试器/编译时,这才起作用!如果您不能包括curl目录,请检查以确保将调试设置为Windows的正确版本.
*Important Note: this will only work if you are using x64 debugger/compiling in x64! If you cannot include the curl directory check to make sure your debug is set to the correct version of Windows.
您可能还需要禁用SSL对等验证:
You may need to disable SSL peer verification as well:
您可能还需要尝试一些其他步骤来使一切正常运行,但是我最终发现它们是不必要的:
Here are some other steps you may need to try to get things running, but I ended up finding them not necessary:
这是我现在可以使用的代码:
Here is my now working code:
#include "curl/curl.h" void testCurl() { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_easy_setopt(curl, CURLOPT_URL, "example/"); #ifdef SKIP_PEER_VERIFICATION curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); #endif #ifdef SKIP_HOSTNAME_VERIFICATION curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); #endif res = curl_easy_perform(curl); if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); curl_easy_cleanup(curl); } curl_global_cleanup(); } int main(){ testCurl(); return 0; }*这是我的老问题在修复之前的其余解释:
* Here is the rest of the explanation of my old problem before it was fixed:
我正在尝试使用cURL进行API调用,这样我就可以开始获取实时库存数据,但是要使其在VS 2017中运行却遇到了困难.我尝试了使用vcpckg安装,步骤如下:
I am trying to use cURL to make an API call so I can start getting real time stock data, but I am running into difficulties getting it to function in VS 2017. I have attempted an install using vcpckg using the following steps:
根据vcpkg文档,我现在应该可以简单地#include,但是找不到该文件夹.如果尝试从vcpkg \ packages \ curl_x86 \ include和#include中包含"include"目录,则可以构建我的项目.我也可以访问某些类,但是如果尝试像本例中那样设置curl_global_init(CURL_GLOBAL_DEFAULT),则会出现链接器错误.
According to vcpkg documentation I should be able to now simply #include , but it can't find the folder. If I try including the "include" directory from vcpkg\packages\curl_x86\include and #include I can build my project. I can also access some of the classes, but if I try and set the curl_global_init(CURL_GLOBAL_DEFAULT) as in this example I get linker errors.
推荐答案
您已经使用vcpkg安装了curl的x86版本(即vcpkg\packages\curl_x86\include中的x86).您需要安装x64版本以匹配您的项目:
You've installed the x86 version of curl with vcpkg (That's the x86 in vcpkg\packages\curl_x86\include). You need to install the x64 version to match your project:
>vcpkg install curl:x64-windows
更多推荐
使cURL与Visual Studios 2017一起使用
发布评论