Curl in C Problem, very simple example returns an error [Linker error] undefined reference to `_imp__curl_easy_init'
#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;
}
This is the code, I got it from the official website of CURL, I added the CURL Library normally into the MinGW (C:\Program Files\CodeBlocks\MinGW\include), but when I try to run this example it returns this error
[Linker error] undefined reference to `imp_curl_easy_init'
if I take away the line with: curl = curl_easy_init(); it works fine.
I'm Compiling with CodeBlocks with MinGW and Using Windows 7.
Thanks in advance
Another thing, is it necessary to compile the cURL library (or any other library) to use ? in my mind just having it included in the program like I'm doing
#include <curl/curl.h>
but I didn't compile the library and I don't ev开发者_如何学编程en know if its necessary, only including it isn't enough ? what else is needed? if its necessary to compile, how to compile it ?
Thanks, I really need to learn to do this =/
Your compiler is not able to "link" with the library.
I'm sorry, I'm not particularly familiar with CodeBlocks, but here is what you need to do: 1) make sure that you downloaded the correct library (mingw32 version)
2) give the following options to the the compiler:
-lcurl -L"c:\libcurl\lib"
c:\libcurl\lib is the directory where libcurl.a is placed
You also need to link with that CURL library. Secondly, include directories are meant for putting header files, not library files.
精彩评论