Getting The Built-in Libcurl Library Working In D On Windows
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.
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.
- Download this collection of files http://www.kalekold.net/downloads/d/libcurl.zip
- 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.
- Open a command prompt and navigate to the 'dmd2\src\druntime' folder.
- Issue the command make -f win32.mak This should build the D runtime libs.
- Navigate to the 'dmd2\src\phobos' folder.
- Issue the command make -f win32.mak This should build the Phobos lib.
- 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.
- I've only tested this on Windows 7 (64bit)
- SSL is not supported with the supplied *.dll file. 1
- In version 2.060 of the Windows D compiler the support for Libcurl is back by default and enabled! Woohoo!