2

I reciently installed the cURL libraries in Dev-C++ using the Packman.exe which is included in the Dev-C++ install. When I try to use #include <curl/curl.h> I do not get an error, so I am assuming that it installed correctly. However, when I try and compile an example from the cURL website, I get the following errors:

[Linker error] undefined reference to _imp__curl_easy_init
[Linker error] undefined reference to _imp__curl_easy_setopt
[Linker error] undefined reference to _imp__curl_easy_perform
[Linker error] undefined reference to _imp__curl_easy_cleanup

The source code I am using is as follows:

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

Thank you! :)

CharlesB
  • 86,532
  • 28
  • 194
  • 218
llk
  • 2,501
  • 7
  • 36
  • 43
  • 1
    @walker Take a look at the [question here](http://stackoverflow.com/questions/6243638/adding-static-libcurl-to-codeblocks-ide/6286504#6286504). Environment setup aside your problem is an exact duplicate of that question. – greatwolf Jun 19 '11 at 05:24

2 Answers2

1

There's two things you need to do to use a (compiled) library:

  • Add the #includes so the compiler knows the library.
  • Add the .libs (or .as) so the linker knows where to find the compiled library's code.

You're probably missing the latter. I don't use Dev-C++ so I can't help with how to add it, though.

Pablo
  • 8,644
  • 2
  • 39
  • 29
  • Ok, Thanks. I had a feeling that was the issue. I guess my question now is how to add the .lib and/or .a files to the linker. – llk Jun 19 '11 at 04:48
0

There are a couple of ways you can add the .lib and/or .a files to the linker in Dev-C++:

The following is what I did when completing the boost tutorial http://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html#link-your-program-to-a-boost-library :

  • Project > Project Options > Directories > Library Directories - and then adding the directory where the *.a files reside.

or

  • Project > Project Options > Parameters > Linker

    -L"C:\Path\To Your\Lib\Files\boost_1_46_1\stage\lib"
    -l-lboost_regex-mgw34-1_46_1
    

I haven't used libcurl but hopefully the process is similar.

ZettaiMuri
  • 18
  • 1