curl.h没有这样的文件或目录


77

我安装了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.

谁能帮我?

Answers:


143

须藤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变体)


3
ubuntu是否有curl-devel包装?虚拟libcurl-dev是由其他几个人提供的,例如libcurl4-openssl-dev对我有用的。
DSM 2012年

抱歉,我的发行版混乱了……应该是libcurl-dev,编辑了答案
n。代词

2
谢谢我使用sudo apt-get install libcurl4-openssl-devg++ test.cpp -L/usr/include/curl/lib -lcurl
user1518451

您不需要-L/usr/include/curl/lib,可能没有这样的路径。
n。代词

2
yum install libcurl-devel应该与另一个包管理器相同
Nachtgold

35

对于那些使用centos并偶然发现此帖子的人:

 $ yum install curl-devel

并在编译程序时example.cpp,链接到curl库:

 $ g++ example.cpp -lcurl -o example

msgstr -o example“创建可执行文件example而不是默认文件a.out

下一行运行example

 $ ./example



3

如果在安装后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/
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.