我安装了curl这个命令(我使用Ubuntu):
sudo apt-get install curl
当我使用g++ test.cpp
测试简单程序时
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* 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);
}
return 0;
}
g++
告诉我:
fatal error: curl/curl.h: No such file or directory
compilation terminated.
谁能帮我?
sudo apt-get install curl-devel
sudo apt-get install libcurl-dev
(将安装默认备选方案)
要么
sudo apt-get install libcurl4-openssl-dev
(OpenSSL变体)
要么
sudo apt-get install libcurl4-gnutls-dev
(gnutls变种)
对于那些使用centos并偶然发现这篇文章的人:
$ yum install curl-devel
在编译程序example.cpp
时,链接到curl库:
$ g++ example.cpp -lcurl -o example
“-o example
”创建可执行文件example
而不是默认的a.out
。
下一行运行example
:
$ ./example
是的,请按照上面的说明下载curl-devel。也不要忘记链接到lib curl:
-L/path/of/curl/lib/libcurl.a (g++)
干杯
如果安装后curl-dev luarocks没有看到标题:
find /usr -name 'curl.h'
Example: /usr/include/x86_64-linux-gnu/curl/curl.h
luarocks install lua-cURL CURL_INCDIR=/usr/include/x86_64-linux-gnu/