c - 对 curl_global_init、curl_easy_init 和其他函数的 undefined reference (C)

标签 c curl libcurl

我正在尝试在 C 中使用 Curl。

我访问了 Curl 官方页面,并复制了示例源代码。

链接如下: http://curl.haxx.se/libcurl/c/sepheaders.html

当我用命令“gcc test.c”运行这段代码时,

控制台显示如下消息。

/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'

我不知道怎么解决。

最佳答案

你没有链接到图书馆。

使用外部库时,您必须链接:

$ gcc test.c -lcurl

最后一个选项告诉 GCC 将 (-l) 与库 curl 链接。

关于c - 对 curl_global_init、curl_easy_init 和其他函数的 undefined reference (C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16476196/

相关文章:

c - fopen 的文件字符串错误?

c - C 新手 - 返回类型错误

c - 是否有 typedef 函数指针的替代语法?

cookies - 在Linux上使用CURL保存Cookie

c++ - curl 回调未返回相同数量的字节

c++ - 结构的大小如何随不同的数据类型而变化

php - json_decode 在我使用 CURL 获取 JSON 数据后返回一个空对象

php - 在 CLI 中静音 PHP cURL 输出

c - 动态链接 LibCURL 时出错

rest - 无法发送正确的休息请求