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

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.


In addition to Joachim Pileborg's answer, it is useful to remember that gcc/g++ linking is sensitive to order and that your linked libraries must follow the things that depend upon them.

$ gcc -lcurl test.c

will fail, missing the same symbols as before. I mention this because I came to this page for forgetting this fact.


I have the same problem, but i use g++ with a make file. This is a linker issue. You need to add option -lcurl on the compiler and on the linker. In my case on the make file:

CC ?= gcc
CXX ?= g++
CXXFLAGS += -I ../src/ -I ./ -DLINUX -lcurl  <- compile option
LDFLAGS += -lrt -lpthread -lcurl      <- linker option

Gerard

Tags:

C

Curl

Libcurl