【问题标题】:Error in installing cURL on a Linux Machine在 Linux 机器上安装 cURL 时出错
【发布时间】:2014-03-24 03:07:38
【问题描述】:

忽略这整个事情,离开这里以获得上下文,请参阅最后的问题。

这是我让自己陷入的一个相当奇怪的情况。我安装了cURL,一切似乎都在工作,除了代码本身。如果我尝试

man curl_easy_init

该函数的手册页出现。我试试

curl -V

curl 7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP 

出现,这意味着我安装正确。我什至去了 /usr/include 并且 curl/curl.h 文件在那里。现在当我尝试一个非常简单的程序时

#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");
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  return 0;
}

在编译时,我收到这些错误:

gcc -Wall test.c
test.c: In function ‘main’:
 test.c:7:12: warning: variable ‘res’ set but not used [-Wunused-but-set-variable]
/tmp/ccT4IJ5R.o: In function `main':
test.c:(.text+0x99): undefined reference to `curl_easy_init'
test.c:(.text+0xc6): undefined reference to `curl_easy_setopt'
test.c:(.text+0xd2): undefined reference to `curl_easy_perform'
test.c:(.text+0xe1): undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status

即使我可以对这些函数中的任何一个执行手册页请求,它也无法正确找到它们。这意味着 curl.h 文件没有正确链接,或者类似的东西。我在安装 curl 库时搞砸了多少?

编辑:找到答案,新问题

在我花时间写完这一切之后,我发现了一个类似的问题,答案是“include -lcurl”并且我的程序编译了。当我已经包含头文件 curl/curl.h 时,为什么还需要这样做?

【问题讨论】:

    标签: linux curl


    【解决方案1】:

    当我已经包含头文件 curl/curl.h 时为什么需要这样做?

    头文件curl.h告诉编译器有关curl库中函数的原型和其他信息,-lcurl告诉链接器在哪里寻找这些函数的定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-14
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 2015-12-26
      相关资源
      最近更新 更多