Cross-compiling Tcl packages

Experiences with cross-compiling Tcl packages ...

sbasi 2016-05-29: I successfully cross-compiled a Tcl extension from Linux for Windows. I did it with cmake[L1 ] and MinGW-w64[L2 ]. The only problem was that cmake did not find the Tcl header files and libraries. Apart from that, it was actually surprisingly simple.

A little more detail:

  • The extension was already set up to be configured and compiled with cmake (see also Cmake)
  • Needed tools: MinGW-w64, cmake
  • Also needed: Tcl header files and libraries for Windows. I got them from tombert's tcltk , and saved them in /home/foo/crosscompile/
  • The next step was to create a toolchain file for cross-compilation:
# Toolchain file to cross-compile for windows

# the name of the target operating system

# which compilers to use for C and C++
SET(CMAKE_C_COMPILER i686-w64-mingw32-cc)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32-c++)

# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH  /usr/i686-w64-mingw32)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search 
# programs in the host environment

# settings for Tcl/tk
# we need to set these variables manually, because cmake does not find them
set (TCL_INCLUDE_PATH /home/foo/crosscompile/include/)
set (TCL_STUB_LIBRARY /home/foo/crosscompile/lib/libtclstub86.a)
set (TK_INCLUDE_PATH /home/foo/crosscompile/include/)
set (TK_STUB_LIBRARY /home/foo/crosscompile/lib/libtkstub86.a)
  • Assuming the toolchain file is saved in /home/foo/crosscompile/toolchain.cmake, the extension can be compiled with:
$ cmake -DCMAKE_TOOLCHAIN_FILE=/home/foo/crosscompile/toolchain.cmake ${path_to_source_dir}
$ make

To be noted that the only dependencies of the extension in question were the standard C library and Tcl/Tk. With more deps, things might get a little harder.