1

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)

  • 1
    try putting `-lcurl` at the start of the command line so `gdc -lcurl myprogram.d` and see what happens. I've seen a bug before that has to do with the order of linking and that might help. – Adam D. Ruppe Jan 01 '15 at 14:51
  • I attempted as you wrote but the same errors happened.What is going on!?!? –  Jan 02 '15 at 02:35

2 Answers2

1

Do you have installed

libcurl4-gnutls-dev

if yes try this:

gdc -lcurl-gnutls myprogram.d -o myprogram 
Kozzi11
  • 2,413
  • 12
  • 17
  • Thank you for your answer, but it doesn't work... The result was same. I tried to do the same thing with official compiler dmd with the option "-L-lphobos2 -L-lcurl" and it worked. –  Jan 09 '15 at 16:02
1

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

Kozzi11
  • 2,413
  • 12
  • 17