【发布时间】:2018-02-14 19:36:22
【问题描述】:
我正在尝试在 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上面的目录在包含路径上。 -
啊,好吧,这是我第一次用第三方库编译 C++。我该如何解决?
-
实际上我确实设法用谷歌搜索了这个——对于其他人来说,你可以使用 -I(大写 I)链接到 C:\curl-7.58.0-win32-mingw\include 谢谢@RichardCritten!
-
你现在应该回答你自己的问题
标签: c++ compilation libcurl