Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use libcurl undefined reference to 'curl_easy_init'

use libcurl to writer some test code. when try to compile, it says undefined reference. already use -lcurl or -L compile option.

root@ubuntu:~/work/test/curlTest# curl-config --libs
-L/usr/lib/x86_64-linux-gnu -lcurl
root@ubuntu:~/work/test/curlTest# gcc -L/usr/lib/x86_64-linux-gnu -lcurl curl.c -o curl
/tmp/ccnFnpaW.o: In function `main':
curl.c:(.text+0xb1): undefined reference to `curl_global_init'
curl.c:(.text+0xbc): undefined reference to `curl_easy_init'
curl.c:(.text+0x109): undefined reference to `curl_easy_setopt'
curl.c:(.text+0x136): undefined reference to `curl_easy_setopt'
curl.c:(.text+0x145): undefined reference to `curl_easy_perform'
collect2: error: ld returned 1 exit status
like image 792
hkx_1030 Avatar asked Jan 27 '15 07:01

hkx_1030


1 Answers

-lcurl should be put in the end of gcc command.

gcc -L/usr/lib/x86_64-linux-gnu curl.c -o curl -lcurl
like image 157
timrau Avatar answered Oct 06 '22 19:10

timrau