2013-05-10 159 views
25

我試圖使用捲曲度C.未定義參考curl_global_init,curl_easy_init和其他功能(C)

我參觀了捲曲的官方網頁,並複製示例源代碼。

下面

是鏈接: 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' 

我不知道如何解決這個問題。

回答

62

你不鏈接圖書館。

使用時,你必須鏈接與它的外部庫:

$ gcc test.c -lcurl 

最後一個選項告訴GCC鏈接(-l)與庫curl

12

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

$ gcc -lcurl test.c

會失敗,因爲之前錯過了相同的符號。我提到這個是因爲我來到這個頁面忘記了這個事實。

0

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

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

傑拉德

1

以前的答案是正確的,但不要忘了添加-o測試產生二進制,否則你會只產生目標文件。

gcc test.c -lcurl -o test