繁体   English   中英

在32位Windows上使用libcurl

[英]Using libcurl on 32bit Windows

我正在尝试在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之上的目录在include路径上。

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

与往常一样,您应该阅读文档

编译程序

您的编译器需要知道libcurl标头所在的位置。 因此,您必须将编译器的包含路径设置为指向安装它们的目录。 'curl-config'[3]工具可用于获取以下信息:

$ curl-config --cflags

我没有使用过libcurl,但是基于此页面,我认为您应该执行的操作是:

g++ -o test.exe -g \
   just_get_output.cpp http_requests.cpp \
   `curl-config --cflags` \
   `curl-config --libs`

现在,所需参数将为您正确放置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM