简体   繁体   中英

(dlang) How to link libcurl using gdc?

I tried to link libcurl to my program but the linker tells me some errors. I've checked that the option "-lcurl" is used.I've also checked that libcurl is installed correctly. The command I tried is:

gdc myprogram.d -o myprogram -lcurl

And the linker told me following errors:

/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'

There are some cases using official compiler dmd but I couldn't find the case with gdc. Any ideas?

(Ubuntu 14.02 LTS amd64)

Do you have installed

libcurl4-gnutls-dev

if yes try this:

gdc -lcurl-gnutls myprogram.d -o myprogram 

Problem is with order how program is link, on Ubuntu it is important to add curl behind libgphobos so this could work:

gdc myprogram.d /usr/lib/gcc/x86_64-linux-gnu/4.8/libgphobos2.a -o myprogram `curl-config --libs`

some more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM