Cross compiling Windows extensions on a Linux host

Zbigniew Diaczyszyn edited this page Nov 13, 2013 · 3 revisions

1) Build the mingw64 toolchain from scratch with the MingGW-w64 Build Script 3.5.0 to be found on 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:

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

# 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:

-I $TCL_INCLUDE -o stretchkey.dll $SRCPATH/stretch.c $SRCPATH/sha256.c \
-L ~/mingw64/mingw-w64-x86_64/lib32 -ltclstub85
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.