我试图将libcurl链接到我的程序,但链接器告诉我一些错误。我已经检查了是否使用了选项"-lcurl"。我还检查了 libcurl 是否正确安装。我尝试的命令是:
gdc myprogram.d -o myprogram -lcurl
链接器告诉我以下错误:
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a(curl.o): In function `_D3std3net4curl4Curl18_sharedStaticCtor1FZv':
/build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:3432: undefined reference to `curl_global_init'
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a(curl.o): In function `_D3std3net4curl4Curl8shutdownMFZv':
/build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:3561: undefined reference to `curl_easy_cleanup'
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a(curl.o): In function `shutdown':
/build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:3561: undefined reference to `curl_easy_cleanup'
/build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:3561: undefined reference to `curl_easy_cleanup'
/build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:3561: undefined reference to `curl_easy_cleanup'
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a(curl.o): In function `_D3std3net4curl4HTTP4Impl6__dtorMFZv':
/build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libphobos/src/../../../../src/libphobos/src/std/net/curl.d:2033: undefined reference to `curl_slist_free_all'
有一些使用官方编译器 dmd 的情况,但我找不到 gdc 的情况。有什么想法吗?
(Ubuntu 14.02 LTS amd64)
您是否已安装
libcurl4-gnutls-dev
如果是,请尝试以下操作:
gdc -lcurl-gnutls myprogram.d -o myprogram
问题在于程序链接的顺序,在 Ubuntu 上,在 libgphobos 后面添加 curl 很重要,这样就可以工作:
gdc myprogram.d /usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a -o myprogram `curl-config --libs`
更多细节