Difference between revisions of "Curl on Windows"
(curl-7.35.0 patches) |
(→Precompiled binaries for Windows) |
||
(11 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | == | + | ==Precompiled binaries for Windows== |
+ | * http://downloads.dlang.org/other/ | ||
− | + | ==Building libcurl static library for DMD32 Windows== | |
− | # http://curl.haxx.se/ | + | Please note that these instructions will compile libcurl static library '''without SSL support'''. |
− | # http:// | + | |
+ | ===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 22: | 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. | + | # Download curl-7.52.1.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD |
− | # Download zlib-1.2. | + | # 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 35: | 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. | + | 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. | + | del /S zlib-1.2.10\*.o curl-7.52.1\*.o curl-7.52.1\*.res |
− | cd zlib-1.2. | + | cd zlib-1.2.10 |
mingw32-make -fwin32/Makefile.gcc | mingw32-make -fwin32/Makefile.gcc | ||
cd .. | cd .. | ||
− | cd curl-7. | + | 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 61: | 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. | + | # Download curl-7.52.1.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD |
− | # Download zlib-1.2. | + | # 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 75: | 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. | + | 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. | + | del /S zlib-1.2.10\*.o curl-7.52.1\*.o curl-7.52.1\*.res |
− | cd zlib-1.2. | + | cd zlib-1.2.10 |
mingw32-make -fwin32/Makefile.gcc | mingw32-make -fwin32/Makefile.gcc | ||
cd .. | cd .. | ||
− | cd curl-7. | + | 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 101: | Line 230: | ||
app64 | app64 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | ---- | ||
+ | [[Category:curl]] | ||
+ | [[Category:Windows]] |
Latest revision as of 22:57, 1 April 2017
Contents
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
- 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
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
- 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.52.1.zip from http://curl.haxx.se/download.html 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
- 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
- Create directory 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.10.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.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