Skip to content
AMDmi3 edited this page Feb 20, 2011 · 3 revisions

This page describes process of cross-compiling win32 binaries of glosm using mingw32 on *nix system.

Preparation steps

  1. First, you need to install mingw32. In consists of multiple packages of which you'll need compiler, binutils, runtime and pthreads port. On FreeBSD, for example, you can get those by installing following ports:

    • devel/mingw32-bin-msvcrt
    • devel/mingw32-binutils
    • devel/mingw32-gcc
    • devel/mingw32-pthreads
  2. Create a directory for cross-compilation environment. It's just convenient to hold all related files in one place, and you'll need it for cmake to search for required files. Lets's name it ${CROSSDIR}. Create ${CROSSDIR}/include ${CROSSDIR}/lib.

  3. Get windows versions of required libraries

    • glew
    • expat (is also available as part of mingw32)
    • SDL or glut (may also try freeglut)

    Extract library files from those (*.lib, *.dll) and place under ${CROSSDIR}/lib. Extract header files (*.h) as well and place them under ${CROSSDIR}/include

  4. Create toolchain file for cmake. This is described on cmake wiki, and this is what I've used:

SET(CMAKE_SYSTEM_NAME Windows)

SET(CMAKE_C_COMPILER mingw32-gcc)
SET(CMAKE_CXX_COMPILER mingw32-g++)

SET(CMAKE_C_FLAGS_RELEASE "-O2 -NDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -NDEBUG")

SET(CMAKE_FIND_ROOT_PATH "/path/to/your/crossdir") # <- change this

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Compilation

cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake /path/to/glosm/sources && make

Testing

Resulting .exe may be tested with wine. Place all required *.dll's (glosm-*.dll, glew, glut, expat etc.) into the same directory and run wine glosm-viewer.exe file.osm

Caveats

  • By default, cmake uses -O3 in Release build. mingw32-gcc 4.5.0 miscompiles viewer with -O3 so CMAKE_CXX_FLAGS_RELEASE should be tweaked as done in the toolchain file above.
Clone this wiki locally