【问题标题】:curl.h no such file or directorycurl.h 没有这样的文件或目录
【发布时间】:2012-07-13 09:00:27
【问题描述】:

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

谁能帮帮我?

【问题讨论】:

    标签: c++ curl


    【解决方案1】:

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

    【讨论】:

    • ubuntu 有curl-devel 包吗?虚拟libcurl-dev 由其他几个提供,例如libcurl4-openssl-dev,这对我有用。
    • 抱歉,我的发行版搞混了……应该是 libcurl-dev,编辑了答案
    • 谢谢我使用sudo apt-get install libcurl4-openssl-devg++ test.cpp -L/usr/include/curl/lib -lcurl
    • 你不需要-L/usr/include/curl/lib,可能没有这样的路径。
    • yum install libcurl-devel 应该与另一个包管理器相同
    【解决方案2】:

    致那些使用centos并偶然发现这篇文章的人:

     $ yum install curl-devel
    

    编译你的程序example.cpp时,链接到curl库:

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

    -o example”创建可执行文件example,而不是默认的a.out

    下一行运行example:

     $ ./example
    

    【讨论】:

      【解决方案3】:

      不用下载 curl,而是下载 libcurl。

      curl 只是应用程序,libcurl 是您的 C++ 程序所需要的

      http://packages.ubuntu.com/quantal/curl

      【讨论】:

        【解决方案4】:

        是的,请按照上面的说明下载 curl-devel。 也不要忘记链接到 lib curl:

        -L/path/of/curl/lib/libcurl.a (g++)
        

        干杯

        【讨论】:

          【解决方案5】:

          如果安装curl-dev luarocks后看不到headers:

          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/
          

          【讨论】:

            猜你喜欢
            • 2014-05-15
            • 1970-01-01
            • 2017-11-13
            • 2014-07-17
            • 2021-07-27
            • 2021-06-24
            • 2015-02-20
            • 1970-01-01
            相关资源
            最近更新 更多