Difference between revisions of "Curl on Windows"

From D Wiki
Jump to: navigation, search
(Building libcurl on Windows)
(MinGW fix)
Line 3: Line 3:
 
As of curl-7.35.0 please apply the following patches.
 
As of curl-7.35.0 please apply the following patches.
 
# http://curl.haxx.se/mail/lib-2014-02/0003.html
 
# http://curl.haxx.se/mail/lib-2014-02/0003.html
# http://curl.haxx.se/mail/lib-2014-02/0097.html
+
# <strike>http://curl.haxx.se/mail/lib-2014-02/0097.html</strike>
 +
# http://curl.haxx.se/mail/lib-2014-02/0118.html
 
This works with dmd 2.065 beta 3. It does not work with dmd 2.064.
 
This works with dmd 2.065 beta 3. It does not work with dmd 2.064.
  

Revision as of 23:22, 13 February 2014

Building libcurl on Windows

As of curl-7.35.0 please apply the following patches.

  1. http://curl.haxx.se/mail/lib-2014-02/0003.html
  2. http://curl.haxx.se/mail/lib-2014-02/0097.html
  3. http://curl.haxx.se/mail/lib-2014-02/0118.html

This works with dmd 2.065 beta 3. It does not work with dmd 2.064.

Required tools

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

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

Building libcurl 32 bit

  1. Create directory C:\BUILD
  2. Download curl-7.33.0.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
  3. Download zlib-1.2.8.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.8
SET INSTALL_DIR=C:\D\dmd2\windows
:: ---------------------------------------------------------------

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

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

cd curl-7.33.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 64 bit

  1. Create directory C:\BUILD
  2. Download curl-7.33.0.zip from http://curl.haxx.se/download.html and extract it into C:\BUILD
  3. Download zlib-1.2.8.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.8
SET INSTALL_DIR=C:\D\dmd2\windows
:: ---------------------------------------------------------------

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

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

cd curl-7.33.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