我安装了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.
任何人都可以帮助我吗?
答案 0 :(得分:111)
sudo apt-get install curl-devel
sudo apt-get install libcurl-dev
(将安装默认备选方案)
OR
sudo apt-get install libcurl4-openssl-dev
(OpenSSL变体)
OR
sudo apt-get install libcurl4-gnutls-dev
(gnutls变种)
答案 1 :(得分:24)
那些使用centos并偶然发现这篇文章的人:
$ yum install curl-devel
在执行你的程序&#34; example.cpp&#34;时,链接到curl外部lib:
$ g++ example.cpp -lcurl -o example
$ ./example
-o example : creates executable example
the next line runs example
答案 2 :(得分:4)
答案 3 :(得分:3)
是的,请按照上面的说明下载curl-devel。 也不要忘记链接到lib curl:
-L/path/of/curl/lib/libcurl.a (g++)
欢呼声
答案 4 :(得分:1)
安装-apt-get install libcurl4-openssl-dev没有帮助。
luarocks install Lua-cURL
Installing https://luarocks.org/lua-curl-0.3.9-1.src.rock
Error: Could not find header file for CURL
No file curl/curl.h in /usr/local/include
No file curl/curl.h in /usr/include
You may have to install CURL in your system and/or pass CURL_DIR or CURL_INCDIR to the luarocks command.
Example: luarocks install lua-curl CURL_DIR=/usr/local
我什至尝试过,但还是不行-
luarocks install Lua-cURL --server=https://luarocks.org/dev CURL_DIR=/usr/bin/curl
答案 5 :(得分:1)
如果在安装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/