Can't successfully compile libcURL sample in CodeBlocks

Greetings all

I am trying to compile this sample libcURL code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include "curl/curl.h"
/* For older cURL versions you will also need
#include <curl/types.h>
#include <curl/easy.h>
*/
#include <string>

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t written = fwrite(ptr, size, nmemb, stream);
    return written;
}

int main(void) {
    CURL *curl;
    FILE *fp;
    CURLcode res;
    char *url = "http://localhost/aaa.txt";
    char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
    curl = curl_easy_init();
    if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        /* always cleanup */
        curl_easy_cleanup(curl);
        fclose(fp);
    }
    return 0;
}


The error I get is:

1
2
3
4
5
6
undefined reference to `_imp__curl_easy_init'
undefined reference to `_imp__curl_easy_setopt'
undefined reference to `_imp__curl_easy_setopt'
undefined reference to `_imp__curl_easy_setopt'
undefined reference to `_imp__curl_easy_perform'
undefined reference to `_imp__curl_easy_cleanup'


All necessary include files seem to be included. I also added these dll files to the project folder:

libcurl.dll
libeay32.dll
libidn-11.dll
libssh2.dll
libssl32.dll
msvcr120.dll
ssleay32.dll
zlib1.dll

What could be causing compilation errors?

Thank you and kind regards,
T
I'm not a Windows user, but try this:

Project->Build Options->Linker Settings in the right pane on separate lines put: -L. -lcurl
That's "lowercase L curl"


Sir thank you very much, that was it! =)

Can you please explain me what did adding "-L. -lcurl" in the linker settings do? I would like to understand it and hopefully avoid this kind of problems in the future. Thank you!
Last edited on
Topic archived. No new replies allowed.