0

I am trying to use curl while developing in eclipse. However i am very new to eclipse for c++ development. While linking libraries i am having the following problems. Any help related to this is really appreciated.

My sample code is :

#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;
}

ERROR IS:

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)

I have tried many solutions available on the internet. But i dont know where i am doing wrong. Some of the solutions are :

Curl linking problem

makefile problems

Make file problem

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

usr/bin/ld: cannot find -l

I know this is linking problem which i am unable to solve. Any help is really appreciated as i am very new to this development environment

Aqeel Abbas
  • 159
  • 4
  • 13
  • You don't seem to specify `-lcurl` correctly. Also post the linker command line and error messages as text, rather than an image please. –  Feb 11 '18 at 07:35
  • Modified as suggested. Can you please guide how to specify `-lcurl` ? as i have read that we have to specify `-lcurl` which i tried to implement as well. but as i am very new, not able to do it correctly – Aqeel Abbas Feb 11 '18 at 07:40
  • You'll find that in your `Project Properties->C/C++ Build->G++ Linker->Libraries`. You can see the generated linker flags below. And `libcurl.a` will be rather found at `/usr/lib` than `/usr/include` BTW. –  Feb 11 '18 at 07:46
  • the path `/usr/include` has all the libraries. and [here](https://www.photobox.co.uk/my/photo/full?photo_id=500571525411) is how i tried to add the libs. What should i write while adding libs ? – Aqeel Abbas Feb 11 '18 at 07:51
  • What is not clear to you in the error message? Are you able to get at difference between `-L` and `-l`? Please read the manual carefully. – 273K Feb 11 '18 at 07:52
  • @AqeelAbbas _"the path /usr/include has all the libraries"_ You seem to have some serious misconceptions, it's not a problem with the IDE. –  Feb 11 '18 at 07:52
  • @S.M. TheDude i am really sorry for being so new to all of this. Can you please check [THIS](https://www.dropbox.com/s/hly54ynyazshb3a/Screenshot%20from%202018-02-11%2012-47-59.png?dl=0) and let me know what do i need to add in it ? – Aqeel Abbas Feb 11 '18 at 08:07
  • @S.M. Thank you for showing the light. I really appreciate that. I have solved it. – Aqeel Abbas Feb 11 '18 at 08:13
  • @TheDude thank you as well. i got it how it works :) omg i have wasted so long time on this small thing. Thanks you again :) – Aqeel Abbas Feb 11 '18 at 08:14
  • @AqeelAbbas Good work! It is much better if you find a solution yourself than if I provide you with an exact solution that yon need only copy-paste. – 273K Feb 11 '18 at 08:22
  • @S.M. you are right. I have found that solution but i wasn't implementing it in the right way. instead of just writing `curl` i kept on writing the path of the libs where they are located. your comment about -L and -l really showed me the right direction. – Aqeel Abbas Feb 11 '18 at 10:00

1 Answers1

0

As i found the answer to the question, just in case if someone like me stumble upon such problems.

Here is the solution

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

We need to add the path for the curl libraries here:

The highlighted Ones

Aqeel Abbas
  • 159
  • 4
  • 13