在eclipse中开发时,我正在尝试使用curl。但是,对于c++开发来说,我对eclipse非常陌生。在链接库时,我遇到了以下问题。任何与此相关的帮助都是非常感谢的。
我的示例代码是:
#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)
我已经尝试了互联网上可用的许多解决方案。但是我不知道我哪里做错了。一些解决方案包括:
Makefile:146: recipe for target 'all' failed #28
我知道这是我无法解决的链接问题。非常感谢您的帮助,因为我对这个开发环境非常陌生。
发布于 2018-02-11 18:34:10
因为我找到了这个问题的答案,以防像我这样的人偶然遇到这样的问题。
以下是解决方案
在Project>>Properties>>C/C++ Build >> Settings >> Tool Settings >> GCC C++ Linker
中
我们需要在这里添加curl库的路径:
https://stackoverflow.com/questions/48729340
复制相似问题