undefined reference to curl_global_init, curl_easy_init and other function(C)

Juneyoung Oh picture Juneyoung Oh · May 10, 2013 · Viewed 68.2k times · Source

I am trying to use Curl in C.

I visited Curl official page, and copied sample source code.

below is the link: http://curl.haxx.se/libcurl/c/sepheaders.html

when I run this code with command "gcc test.c",

the console shows message like below.

/tmp/cc1vsivQ.o: In function `main':
test.c:(.text+0xe1): undefined reference to `curl_global_init'
test.c:(.text+0xe6): undefined reference to `curl_easy_init'
test.c:(.text+0x10c): undefined reference to `curl_easy_setopt'
test.c:(.text+0x12e): undefined reference to `curl_easy_setopt'
test.c:(.text+0x150): undefined reference to `curl_easy_setopt'
test.c:(.text+0x17e): undefined reference to `curl_easy_cleanup'
test.c:(.text+0x1b3): undefined reference to `curl_easy_cleanup'
test.c:(.text+0x1db): undefined reference to `curl_easy_setopt'
test.c:(.text+0x1e7): undefined reference to `curl_easy_perform'
test.c:(.text+0x1ff): undefined reference to `curl_easy_cleanup'

I do not know how to solve this.

Answer

Some programmer dude picture Some programmer dude · May 10, 2013

You don't link with the library.

When using an external library you must link with it:

$ gcc test.c -lcurl

The last option tells GCC to link (-l) with the library curl.