curl的一番折腾

在windows上使用curl

在编译的时候出现
fatal error C1083: Can not open include file: “curl / curl.h”: No such file or directory

解决:

需要连接lib和头文件
使用mingw-w64编译
移动到需要编译的文件位置
然后按照下图链接lib和头文件
如图所示
gcc -o xxx 输出名字xxx.exe的可执行文件
-I(大写的i)后面跟着的是curl/curl.h头文件的位置
-L(大写的l)后面跟着的是libcurl.a的位置
-lcurl 是-l(小写的L)+curl(也就是查找libcurl)
@@有可能需要做:把.\curl-7.78.0-win64-mingw\bin,也就是你的curl.exe和libcurl-x64所在的路径在系统全局变量中的path里添加上

成功!!

成功!
下面是curl官方下载的样本代码http-post.c

#include <stdio.h>
#include <curl/curl.h>
 
int main(void)
{
  CURL *curl;
  CURLcode res;
 
  /* In windows, this will init the winsock stuff */
  curl_global_init(CURL_GLOBAL_ALL);
 
  /* get a curl handle */
  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.bilibili.com");
    /* Now specify the POST data */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
 
    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));
 
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值