链接curl库问题eclipse

时间:2018-02-11 07:32:07

标签: c++ eclipse curl makefile linker-errors

我试图在eclipse中开发时使用curl。但是我对eclipse的c ++开发很新。在链接库时,我遇到了以下问题。任何与此相关的帮助都非常感谢。

我的示例代码是:

#include <iostream>
#include <string>
#include <curl/curl.h>


static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main(void)
{
  CURL *curl;
  CURLcode res;
  std::string readBuffer;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    std::cout << readBuffer << std::endl;
  }
  return 0;
}

错误是:

12:37:29 **** Incremental Build of configuration Debug for project Bestapi ****
make all 
Building target: Bestapi
Invoking: GCC C++ Linker
g++ -L/usr/include -o "Bestapi"  ./bestapi.o   -l/usr/include
/usr/bin/ld: cannot find -l/usr/include
collect2: error: ld returned 1 exit status
makefile:44: recipe for target 'Bestapi' failed
make: *** [Bestapi] Error 1

12:37:30 Build Finished (took 366ms)

我在互联网上尝试了很多解决方案。但我不知道我在哪里做错了。一些解决方案是:

Curl linking problem

makefile problems

Make file problem

Makefile:146: recipe for target 'all' failed #28

usr/bin/ld: cannot find -l

我知道这是我无法解决的问题。任何帮助都非常感谢,因为我对这个开发环境很陌生

1 个答案:

答案 0 :(得分:0)

当我找到问题的答案时,以防万一像我这样的人偶然发现这些问题。

这是解决方案

Project>>Properties>>C/C++ Build >> Settings >> Tool Settings >> GCC C++ Linker

我们需要在这里添加curl库的路径:

The highlighted Ones