Getting The Built-in Libcurl Library Working In D On Windows

View 2 Comments - July 01, 2012

I've recently needed to retrieve data from the internet using D so this blog deals with getting the built-in library for doing such things working as it should.

In D's standard library there is a neat wrapper around libcurl called  std.net.curl  but in version 2.059 of the Windows D compiler the support for this library is disabled. Here's how to get it working.

First of all, what is libcurl?

cURL is a well known command line tool for transfering data over a network, libcurl is the library version that other programs can use. This is from the libcurl website:

libcurl is a free and easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), file transfer resume, http proxy tunneling and more! libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...

D fully supports this library but in the Windows version it's disabled so let's switch it back on.

Recompile Phobos

Phobos is the standard runtime library that comes with the D compiler and contains  std.net.curl . We just need to follow these steps to enable phobos to use the correct library files during compilation.

  1. Download this collection of files http://www.kalekold.net/downloads/d/libcurl.zip
  2. Once extracted place the files into your 'dmd2' folder (the file structure is the same.) The *.lib and *.dll files are pretty straightforward to copy but the win32.mak file will overwrite one that already exists! So make a backup before over writing this file. The win32.mak.patch file is supplied just in case you want to patch your existing file manually.
  3. Open a command prompt and navigate to the 'dmd2\src\druntime' folder.
  4. Issue the command  make -f win32.mak  This should build the D runtime libs.
  5. Navigate to the 'dmd2\src\phobos' folder.
  6. Issue the command  make -f win32.mak  This should build the Phobos lib.
  7. Move the 'phobos.lib' file from that folder to the 'dmd2\windows\lib' folder. You may want to take a backup of your existing one.

These steps should now enable you to use the  std.net.curl  library successfully. If you want to distribute your application you'll need to include the 'libcurl.dll' that is in the download along with it. Just drop it in the same directory as your application and it should work fine.

Caveats

  1. I've only tested this on Windows 7 (64bit)
  2. SSL is not supported with the supplied *.dll file. 1
  3. In version 2.060 of the Windows D compiler the support for Libcurl is back by default and enabled! Woohoo!
Tagged: D Library Windows
Name
Comment
To post, select Spock.