Difference between revisions of "Curl on Windows"

From D Wiki
Jump to: navigation, search
(Building libcurl on Windows)
(Precompiled binaries for Windows)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Building libcurl on Windows==
+
==Precompiled binaries for Windows==
 +
* http://downloads.dlang.org/other/
  
As of curl-7.35.0 please apply the following patches.
+
==Building libcurl static library for DMD32 Windows==
# http://curl.haxx.se/mail/lib-2014-02/0003.html
+
Please note that these instructions will compile libcurl static library '''without SSL support'''.
# http://curl.haxx.se/mail/lib-2014-02/0097.html
+
 
This works with dmd 2.065 beta 3. It does not work with dmd 2.064.
+
===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:
 +
<syntaxhighlight lang=c>
 +
#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
 +
</syntaxhighlight>
 +
 
 +
Open include\curl\curlrules.h and add '''|| defined(__DMC__)''' to line 207:
 +
<syntaxhighlight lang=c>
 +
#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__)
 +
</syntaxhighlight>
 +
 
 +
Open lib\config-win32.h and add '''&& !defined(__DMC__)''' to line 566
 +
<syntaxhighlight lang=c>
 +
#if !defined(__SALFORDC__) && !defined(__BORLANDC__) && !defined(__DMC__)
 +
#define HAVE_STRUCT_SOCKADDR_STORAGE 1
 +
#endif
 +
</syntaxhighlight>
 +
 
 +
Open lib\curl_setup.h and add the following to line 504
 +
<syntaxhighlight lang=c>
 +
#if defined(__DMC__)
 +
#  undef USE_THREADS_POSIX
 +
#  undef USE_THREADS_WIN32
 +
#endif
 +
</syntaxhighlight>
 +
 
 +
Save the following as C:\BUILD\curl-7.37.0\lib\Makefile.dmc
 +
<syntaxhighlight lang=make>
 +
###########################################################################
 +
#
 +
## 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)
 +
</syntaxhighlight>
 +
 
 +
* cd C:\BUILD\curl-7.37.0\lib\
 +
* set PATH=C:\Dev\MinGW\bin;C:\dm\bin
 +
* mingw32-make -f Makefile.dmc
 +
 
 +
===Using the static lib===
 +
 
 +
Since dmd 2.069.0 all the curl symbols need to be exported so that std.net.curl can load them from the executable. This can be achieved by additionally linking with export_curl.def.
 +
 
 +
<pre>
 +
EXETYPE NT
 +
EXPORTS
 +
curl_global_init
 +
curl_global_cleanup
 +
curl_version_info
 +
curl_easy_init
 +
curl_easy_setopt
 +
curl_easy_perform
 +
curl_easy_duphandle
 +
curl_easy_strerror
 +
curl_easy_pause
 +
curl_easy_cleanup
 +
curl_slist_append
 +
curl_slist_free_all
 +
</pre>
 +
 
 +
<code>
 +
dmd myprog.d curl_static_dmc.lib export_curl.def
 +
</code>
 +
 
 +
==Building libcurl.dll on Windows==
  
 
===Required tools===
 
===Required tools===
Line 23: Line 151:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Building libcurl 32 bit===
+
===Building libcurl.dll 32 bit with SSL support===
 
# Create directory C:\BUILD
 
# Create directory C:\BUILD
# Download curl-7.33.0.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
+
# Download curl-7.52.1.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
+
# Download zlib-1.2.10.tar.gz from http://zlib.net/ and extract it into C:\BUILD
 
# Save the following batch file as C:\BUILD\build-curl32.bat
 
# Save the following batch file as C:\BUILD\build-curl32.bat
 
# Run build-curl32 from Windows command prompt
 
# Run build-curl32 from Windows command prompt
Line 36: Line 164:
 
:: 2) Path to Digital Mars's implib.exe
 
:: 2) Path to Digital Mars's implib.exe
 
SET PATH=C:\Dev\MinGW\bin;C:\Dev\dm\bin;
 
SET PATH=C:\Dev\MinGW\bin;C:\Dev\dm\bin;
SET ZLIB_PATH=C:\BUILD\zlib-1.2.8
+
SET ZLIB_PATH=C:\BUILD\zlib-1.2.10
 
SET INSTALL_DIR=C:\D\dmd2\windows
 
SET INSTALL_DIR=C:\D\dmd2\windows
 
:: ---------------------------------------------------------------
 
:: ---------------------------------------------------------------
  
 
:: Delete object files from previous build
 
:: Delete object files from previous build
del /S zlib-1.2.8\*.o curl-7.33.0\*.o curl-7.33.0\*.res
+
del /S zlib-1.2.10\*.o curl-7.52.1\*.o curl-7.52.1\*.res
  
cd zlib-1.2.8
+
cd zlib-1.2.10
 
mingw32-make -fwin32/Makefile.gcc
 
mingw32-make -fwin32/Makefile.gcc
 
cd ..
 
cd ..
  
cd curl-7.33.0
+
cd curl-7.52.1
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib LDFLAGS=-static
+
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib-ipv6 LDFLAGS=-static
 
strip -s lib\libcurl.dll
 
strip -s lib\libcurl.dll
  
Line 62: Line 190:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Building libcurl 64 bit===
+
===Building libcurl.dll 64 bit with SSL support===
 
# Create directory C:\BUILD
 
# Create directory C:\BUILD
# Download curl-7.33.0.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
+
# Download curl-7.52.1.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
+
# Download zlib-1.2.10.tar.gz from http://zlib.net/ and extract it into C:\BUILD
 
# Save the following batch file as C:\BUILD\build-curl64.bat
 
# Save the following batch file as C:\BUILD\build-curl64.bat
 
# Run build-curl64 from Windows command prompt
 
# Run build-curl64 from Windows command prompt
Line 76: Line 204:
 
:: 3) Path to pexports.exe (http://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/)
 
:: 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 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 ZLIB_PATH=C:\BUILD\zlib-1.2.10
 
SET INSTALL_DIR=C:\D\dmd2\windows
 
SET INSTALL_DIR=C:\D\dmd2\windows
 
:: ---------------------------------------------------------------
 
:: ---------------------------------------------------------------
  
 
:: Delete object files from previous build
 
:: Delete object files from previous build
del /S zlib-1.2.8\*.o curl-7.33.0\*.o curl-7.33.0\*.res
+
del /S zlib-1.2.10\*.o curl-7.52.1\*.o curl-7.52.1\*.res
  
cd zlib-1.2.8
+
cd zlib-1.2.10
 
mingw32-make -fwin32/Makefile.gcc
 
mingw32-make -fwin32/Makefile.gcc
 
cd ..
 
cd ..
  
cd curl-7.33.0
+
cd curl-7.52.1
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib LDFLAGS=-static
+
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib-ipv6 LDFLAGS=-static
 
strip -s lib\libcurl.dll
 
strip -s lib\libcurl.dll
  
Line 102: Line 230:
 
app64
 
app64
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
----
 +
[[Category:curl]]
 +
[[Category:Windows]]

Latest revision as of 22:57, 1 April 2017

Precompiled binaries for Windows

Building libcurl static library for DMD32 Windows

Please note that these instructions will compile libcurl static library without SSL support.

Required tools

Building curl_static_dmc.lib

  1. Create directory C:\BUILD
  2. Download http://curl.haxx.se/download/curl-7.37.0.zip and extract it into C:\BUILD
  3. 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

Using the static lib

Since dmd 2.069.0 all the curl symbols need to be exported so that std.net.curl can load them from the executable. This can be achieved by additionally linking with export_curl.def.

EXETYPE NT
EXPORTS
curl_global_init
curl_global_cleanup
curl_version_info
curl_easy_init
curl_easy_setopt
curl_easy_perform
curl_easy_duphandle
curl_easy_strerror
curl_easy_pause
curl_easy_cleanup
curl_slist_append
curl_slist_free_all

dmd myprog.d curl_static_dmc.lib export_curl.def

Building libcurl.dll on Windows

Required tools

import std.net.curl;
import std.stdio;

void main()
{
	writeln(get("https://google.com/"));
}

Building libcurl.dll 32 bit with SSL support

  1. Create directory C:\BUILD
  2. Download curl-7.52.1.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
  3. Download zlib-1.2.10.tar.gz from http://zlib.net/ and extract it into C:\BUILD
  4. Save the following batch file as C:\BUILD\build-curl32.bat
  5. 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.10
SET INSTALL_DIR=C:\D\dmd2\windows
:: ---------------------------------------------------------------

:: Delete object files from previous build
del /S zlib-1.2.10\*.o curl-7.52.1\*.o curl-7.52.1\*.res

cd zlib-1.2.10
mingw32-make -fwin32/Makefile.gcc
cd ..

cd curl-7.52.1
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib-ipv6 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

  1. Create directory C:\BUILD
  2. Download curl-7.52.1.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
  3. Download zlib-1.2.10.tar.gz from http://zlib.net/ and extract it into C:\BUILD
  4. Save the following batch file as C:\BUILD\build-curl64.bat
  5. 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.10
SET INSTALL_DIR=C:\D\dmd2\windows
:: ---------------------------------------------------------------

:: Delete object files from previous build
del /S zlib-1.2.10\*.o curl-7.52.1\*.o curl-7.52.1\*.res

cd zlib-1.2.10
mingw32-make -fwin32/Makefile.gcc
cd ..

cd curl-7.52.1
mingw32-make -C lib -f Makefile.m32 CFG=mingw32-winssl-zlib-ipv6 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