c++ - 在 32 位 Windows 上使用 libcurl

标签 c++ compilation libcurl

我正在尝试在 32 位 Windows 安装上使用 libcurl 进行编译。我正在使用 mingw 作为编译器。我从 https://bintray.com/artifact/download/vszakats/generic/curl-7.58.0-win32-mingw.7z 下载了 libcurl并使用它来编译我的项目:

g++ -o test.exe -g just_get_output.cpp http_requests.cpp -L C:\curl-7.58.0-win32-mingw\lib -lcurl -lpsapi

所有的 libcurl 代码都在 http_requests.cpp 中:

#include <stdio.h>
#define CURL_STATICLIB
#include <curl/curl.h>

// https://kukuruku.co/post/a-cheat-sheet-for-http-libraries-in-c/

int http_post(char* url, char* data)
{
    CURL *curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_ALL);

    curl = curl_easy_init();
    if(curl) 
    {
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        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();
    return 0;
}

我的主要代码,经过大量编辑:

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <windows.h>
#include <tchar.h>
#include <psapi.h>
#include "http_requests.cpp"

int main( void ) {
    std::string info = "test";
    std::string url = "192.168.30.1:8080";
    http_post(url, info)
    return 0;
}

我得到的错误:

Z:\>g++ -o test.exe -g just_get_output.cpp http_requests.cpp -L C:\curl-7.58.0-win32-mingw\lib\libcurl.a -lcurl -lpsapi
In file included from just_get_output.cpp:11:0:
http_requests.cpp:3:23: fatal error: curl/curl.h: No such file or directory
 #include <curl/curl.h>
                       ^
compilation terminated.
http_requests.cpp:3:23: fatal error: curl/curl.h: No such file or directory
 #include <curl/curl.h>
                       ^
compilation terminated.

这是怎么回事?我预编译的 libcurl.a 位于正确的目录中,我使用 -L 和 -l 正确链接它,但我不确定我缺少什么。

最佳答案

这是一个编译错误。它期望 curl/curl.h 上面的目录位于包含路径上。

对于其他人,您可以使用 -I(大写 I)链接到 C:\curl-7.58.0-win32-mingw\include。谢谢@RichardCritten!

关于c++ - 在 32 位 Windows 上使用 libcurl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48794904/

相关文章:

c++ - 为什么处理多个数据流比处理一个数据流慢?

ffmpeg - 编译 FFMPEG 时找不到静态 x265

在一个请求中下载正文之前,C++ libcurl 检查 header

c++ - 你知道 Firefox 3 使用哪个库来获取 "download completed"信息吗?

c# - 从外部应用程序读取屏幕上的文本。 API Hook ?

c++ - 如何在链接时修复 Makefile 错误 'unrecognized reference'?

java - java编译器如何找到没有头文件的类?

c++ - C++共享库中基类的 undefined symbol 错误

c - 使用 libcurl 在 C 中检索数据

c++ - 使用 libcurl 和 C++ 将图片上传到受密码保护的目录