使用libcurl编写一些测试代码.当尝试编译时,它表示未定义的引用.已经使用-lcurl或-L编译选项.
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
最佳答案
-lcurl应该放在gcc命令的末尾.
gcc -L/usr/lib/x86_64-linux-gnu curl.c -o curl -lcurl