Curl on Windows
Contents
Building libcurl static library for DMD32 Windows
Please note that these instructions will compile libcurl static library without SSL support.
Required tools
- MinGW-make (http://www.mingw.org)
- Digital Mars Compiler (http://ftp.digitalmars.com/Digital_Mars_C++/Patch/dm857c.zip)
Building curl_static_dmc.lib
- Create directory C:\BUILD
- Download http://curl.haxx.se/download/curl-7.37.0.zip and extract it into C:\BUILD
- cd C:\BUILD\curl-7.37.0
Open include\curl\curlbuild.h in your favorite editor and add the following to line 188:
#elif defined(__DMC__)
# define CURL_SIZEOF_LONG 4
# define CURL_TYPEOF_CURL_OFF_T long long
# define CURL_FORMAT_CURL_OFF_T "lld"
# define CURL_FORMAT_CURL_OFF_TU "llu"
# define CURL_FORMAT_OFF_T "%lld"
# define CURL_SIZEOF_CURL_OFF_T 8
# define CURL_SUFFIX_CURL_OFF_T LL
# define CURL_SUFFIX_CURL_OFF_TU ULL
# define CURL_TYPEOF_CURL_SOCKLEN_T int
# define CURL_SIZEOF_CURL_SOCKLEN_T 4
Open include\curl\curlrules.h and add || defined(__DMC__) to line 207:
#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
defined(__ILEC400__) || defined(__DMC__)
Open lib\config-win32.h and add && !defined(__DMC__) to line 566
#if !defined(__SALFORDC__) && !defined(__BORLANDC__) && !defined(__DMC__)
#define HAVE_STRUCT_SOCKADDR_STORAGE 1
#endif
Open lib\curl_setup.h and add the following to line 504
#if defined(__DMC__)
# undef USE_THREADS_POSIX
# undef USE_THREADS_WIN32
#endif
Save the following as C:\BUILD\curl-7.37.0\lib\Makefile.dmc
###########################################################################
#
## Makefile for building curl_static_dmc.lib with DMC - Digital Mars Compiler
## http://ftp.digitalmars.com/Digital_Mars_C++/Patch/dm857c.zip
##
## Please run me with mingw32-make!
##
## Usage:
## 1) Set environment vars: path\to\mingw32\bin;path\to\dm\bin
## Example:
## SET PATH=C:\Dev\MinGW\bin;C:\dm\bin
##
## 2) Build
## mingw32-make -f Makefile.dmc
##
#
###########################################################################
BIN=curl_static_dmc.lib
## REQUIRED
CFLAGS=-I. -I../include -DBUILDING_LIBCURL -D_WIN32_WINNT=0x0400 -DCURL_DISABLE_LDAP
## OPTIONAL. Please add # to the start of line if you want the feature
CFLAGS+=-DCURL_DISABLE_POP3
CFLAGS+=-DCURL_DISABLE_DICT
CFLAGS+=-DCURL_DISABLE_FILE
CFLAGS+=-DCURL_DISABLE_GOPHER
CFLAGS+=-DCURL_DISABLE_IMAP
CFLAGS+=-DCURL_DISABLE_RTSP
CFLAGS+=-DCURL_DISABLE_TELNET
CFLAGS+=-DCURL_DISABLE_TFTP
include Makefile.inc
SOURCES=$(LIB_CFILES) $(LIB_VTLS_CFILES)
OBJS=$(patsubst %.c,%.obj,$(SOURCES))
all: $(BIN)
$(BIN): $(OBJS)
lib -p32 -c $(BIN) $(OBJS)
%.obj: %.c
dmc $(CFLAGS) -c $< -o$@
clean:
del $(BIN) $(OBJS)
- cd C:\BUILD\curl-7.37.0\lib\
- set PATH=C:\Dev\MinGW\bin;C:\dm\bin
- mingw32-make -f Makefile.dmc
Building libcurl.dll on Windows
Required tools
- MinGW (http://www.mingw.org)
- Digital Mars' implib (http://ftp.digitalmars.com/bup.zip)
- MinGW-w64 (http://mingw-w64.sourceforge.net/)
- Microsoft Librarian (lib.exe)
- pexports (http://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/)
- Sample program app.d
import std.net.curl;
import std.stdio;
void main()
{
writeln(get("https://google.com/"));
}
Building libcurl.dll 32 bit with SSL support
- Create directory C:\BUILD
- Download curl-7.36.0.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
- Download zlib-1.2.8.tar.gz from http://zlib.net/ and extract it into C:\BUILD
- Save the following batch file as C:\BUILD\build-curl32.bat
- Run build-curl32 from Windows command prompt
@echo off
:: 1) Path to MinGW\bin
:: 2) Path to Digital Mars's implib.exe
SET PATH=C:\Dev\MinGW\bin;C:\Dev\dm\bin;
SET ZLIB_PATH=C:\BUILD\zlib-1.2.8
SET INSTALL_DIR=C:\D\dmd2\windows
:: ---------------------------------------------------------------
:: Delete object files from previous build
del /S zlib-1.2.8\*.o curl-7.36.0\*.o curl-7.36.0\*.res
cd zlib-1.2.8
mingw32-make -fwin32/Makefile.gcc
cd ..
cd curl-7.36.0
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib LDFLAGS=-static
strip -s lib\libcurl.dll
mkdir %INSTALL_DIR%\bin %INSTALL_DIR%\lib
copy lib\libcurl.dll %INSTALL_DIR%\bin
implib /system %INSTALL_DIR%\lib\curl.lib lib\libcurl.dll
cd ..
:: Build sample
SET PATH=%INSTALL_DIR%\bin
dmd app.d -ofapp32.exe
app32
Building libcurl.dll 64 bit with SSL support
- Create directory C:\BUILD
- Download curl-7.36.0.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
- Download zlib-1.2.8.tar.gz from http://zlib.net/ and extract it into C:\BUILD
- Save the following batch file as C:\BUILD\build-curl64.bat
- Run build-curl64 from Windows command prompt
@echo off
:: 1) Path to MinGW-w64\bin
:: 2) Path to Microsoft LIB.exe
:: 3) Path to pexports.exe (http://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/)
SET PATH=C:\Dev\MinGW64\bin;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\Bin\amd64;C:\Dev\MinGW\bin
SET ZLIB_PATH=C:\BUILD\zlib-1.2.8
SET INSTALL_DIR=C:\D\dmd2\windows
:: ---------------------------------------------------------------
:: Delete object files from previous build
del /S zlib-1.2.8\*.o curl-7.36.0\*.o curl-7.36.0\*.res
cd zlib-1.2.8
mingw32-make -fwin32/Makefile.gcc
cd ..
cd curl-7.36.0
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib LDFLAGS=-static
strip -s lib\libcurl.dll
mkdir %INSTALL_DIR%\bin64 %INSTALL_DIR%\lib64
copy lib\libcurl.dll %INSTALL_DIR%\bin64
pexports lib\libcurl.dll > curl.def
lib /MACHINE:X64 /DEF:curl.def /OUT:%INSTALL_DIR%\lib64\curl.lib
cd ..
:: Build sample
SET PATH=%INSTALL_DIR%\bin64;%INSTALL_DIR%\bin
dmd -m64 app.d -ofapp64.exe
app64