-
Notifications
You must be signed in to change notification settings - Fork 63
Cross compiling Windows extensions on a Linux host
1) Build the mingw64 toolchain from scratch with the MingGW-w64 Build Script 3.5.0 to be found on http://zeranoe.com/scripts/mingw_w64_build/mingw-w64-build-3.5.0 which is actually (Nov 2013) based on MinGW-w64 3.0.0 and GCC 4.8.1.
./mingw-w64-build-3.5.0 --build-type=multi --default-configure --disable-shared --enable-gendef
In the directories mingw-w64-i686 and mingw-w64-x86_64 you will find all the necessary toolchain binaries.
2) Take the mingw64 gcc into your PATH variable, e.g. for 32bit version:
export PATH="~/mingw64/mingw-w64-i686/bin:$PATH"
and build a Windows version of Tcl to get an appropriate libstubtcl85.a. Note: You have to replace the macro EXCEPTION_REGISTRATION by TCL_EXCEPTION_REGISTRATION in the files tclWin32Dll.c, tclWinChan.c and tclWinFCmd.c
Alexey Pavlov is offering a patch on his github site: https://github.com/Alexpux/mingw-builds/blob/master/patches/tcl/tcl-8.6.1-mingwexcept.patch
If you rebuild the Tcl system don’t forget to type before configuration:
make clean
make distclean
3) Then go on to build your extension with defining the prefixes, the source, the include and the lib path, e.g.:
# 32bit GCCPATH=~/mingw64/mingw-w64-i686/bin/ PREFIX=$GCCPATH/i686-w64-mingw32
# 64bit # GCCPATH=~/mingw-w64-x86_64/bin # PREFIX=$GCCPATH/x86_64-w64-mingw32
export CC=$PREFIX-gcc export CXX=$PREFIX-g++ export CPP=$PREFIX-cpp export RANLIB=$PREFIX-ranlib export LD=$PREFIX-ld ...
Then we finally start the build process:
$CC -Wall -shared -DUSE_TCL_STUBS \
-I $TCL_INCLUDE -o my_extension.dll $SRCPATH/my_extension.c \
-L $TCL_WIN_BUILD -ltclstub85
Note: To successfully build the stretchkey extension we have to add the definition -DRUNTIME_ENDIAN otherwise Tcllib’s SHA256 module will offer wrong results. In the following 32bit example libtclstub85.a has been copied into the mingw64 32bit library:
$CC -Wall -shared -DRUNTIME_ENDIAN -DUSE_TCL_STUBS \
-I $TCL_INCLUDE -o stretchkey.dll $SRCPATH/stretch.c $SRCPATH/sha256.c \
-L ~/mingw64/mingw-w64-x86_64/lib32 -ltclstub85