Having issues using the cURL libraries for Dev-C++ in Windows 7
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! :)
There's two things you need to do to use a (compiled) library:
- Add the
#include
s so the compiler knows the library. - Add the
.lib
s (or.a
s) 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.
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.
精彩评论