我尝试将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)
答案 0 :(得分:1)
你安装了
吗?libcurl4-gnutls-dev
如果是,试试这个:
gdc -lcurl-gnutls myprogram.d -o myprogram
答案 1 :(得分:1)
问题是关于程序如何链接的顺序,在Ubuntu上重要的是在libgphobos后面添加curl以便这可以工作:
gdc myprogram.d /usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a -o myprogram `curl-config --libs`