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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11471690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:10:32  来源:igfitidea点击:

curl.h no such file or directory

c++curl

提问by user1518451

I installed curl this command (i use Ubuntu):

我安装了 curl 这个命令(我使用 Ubuntu):

sudo apt-get install curl

When I test simple program using g++ test.cpp

当我使用 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++shows me:

g++给我看:

fatal error: curl/curl.h: No such file or directory
compilation terminated.

Can anyone help me?

谁能帮我?

回答by n. 'pronouns' m.

sudo apt-get install curl-devel

sudo apt-get install curl-devel

sudo apt-get install libcurl-dev

(will install the default alternative)

(将安装默认的替代品)

OR

或者

sudo apt-get install libcurl4-openssl-dev

(the OpenSSL variant)

(OpenSSL 变体)

OR

或者

sudo apt-get install libcurl4-gnutls-dev

(the gnutls variant)

(gnutls 变体)

回答by mouserat

To those who use centos and have stumbled upon this post :

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

 $ yum install curl-devel

and when compiling your program example.cpp, link to the curl library:

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

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

"-o example" creates the executable exampleinstead of the default a.out.

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

The next line runs example:

下一行运行example

 $ ./example

回答by roymustang86

Instead of downloading curl, down libcurl.

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

curl is just the application, libcurl is what you need for your C++ program

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

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

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

回答by Moataz Elmasry

yes please download curl-devel as instructed above. also don't forget to link to lib curl:

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

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

cheers

干杯

回答by bujnos

If after the installation curl-dev luarocks does not see the headers:

如果安装 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/