簡體   English   中英

對 curl_global_init、curl_easy_init 和其他函數的未定義引用(C)

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

我正在嘗試在 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

除了 Joachim Pileborg 的回答之外,記住 gcc/g++ 鏈接對順序很敏感並且你的鏈接庫必須遵循依賴它們的東西是很有用的。

$ gcc -lcurl test.c

將失敗,缺少與以前相同的符號。 我提到這一點是因為我來到這個頁面是為了忘記這個事實。

我有同樣的問題,但我將 g++ 與 make 文件一起使用。 這是鏈接器問題。 您需要在編譯器和鏈接器上添加選項 -lcurl。 在我的情況下,make 文件:

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

傑拉德

根據事情的嚴重程度,您可能需要在 LDFLAGS 中使用 -L/somewhere 來讓鏈接器知道庫的位置。 ldconfig 應該在每次啟動時撿起它們並找到它們,但是在新機器上它可能需要一點刺激,比如在 /etc/ld.so.conf 中添加一個目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM