2013-05-10 152 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