The question seems straight forward. I tried a lot of things just to include curl in my C project using the code::blocks ide but to no avail.
I would like to use cURL's library for my console app project that needs http capabilities.
If anyone had successfully done so, then your help is very much appreciated. :)
What happened previously:
-I copied all cURL files to my project and linked the libraries (the ones with .a or .lib ext.)
-Then when I build the project. A lot of undefined reference showed up.
This is the code I was testing:
curl_global_init( CURL_GLOBAL_ALL );
CURL * myHandle;
myHandle = curl_easy_init ( ) ;
curl_easy_setopt(myHandle, CURLOPT_URL, "http://www.example.com");
result = curl_easy_perform( myHandle );
curl_easy_cleanup( myHandle );
||=== Fa, Release ===|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_global_init'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_init'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_setopt'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_perform'|
obj\Release\main.o:main.c|| undefined reference to `_imp__curl_easy_cleanup'|
||=== Build finished: 5 errors, 0 warnings ===|
Go to your project "Build Options" -> "Linker" tab and so you have two choices:
If your library is (correctly) installed system-wide, write in "other linker options" the libs as if you were using your compiler directly.
For GCC you'd write
-lcurl. You may also use this with a path instruction like
Wl,-rpath,/path/to/your/library -lMyLib. Obviously it depends on the compiler and system setup.
Add the library in "Link libraries" on the left. Click the "Add" button and browse to your library file.
Take a look at this A.3 — Using libraries with Code::Blocks for some pictures. Googling around will show you more.