Sunday, November 13, 2011

Building Rockbox simulator in Windows using Cygwin

When building the Rockbox simulator under Cygwin in Windows, an important thing to keep in mind is that the simulator is normally being cross compiled. It is being built within Cygwin using Cygwin tools, but it's built to run outside Cygwin, as a normal Windows application.

When using the sdl package from http://download.rockbox.org/cygwin/, tools/configure doesn't need to be told about the cross-compiling because sdl-config adds the -mno-cygwin switch. That switch tells the old GCC 3.4.4 compiler to build a standard Windows application instead of a Cygwin application. The switch is only really meant for compiling parts of Cygwin which must not depend on Cygwin, but it works.

If you instead use SDL from libsdl.org, the -mno-cygwin flag won't be added and an attempt will be made to compile the simulator as a Cygwin application. This fails with many errors in /usr/include/sys/reent.h because Rockbox firmware/include/_ansi.h is included instead of /usr/include/_ansi.h.

If you try to use the -mno-cygwin flag in Cygwin gcc-4, you'll be told "The -mno-cygwin flag has been removed; use a mingw-targeted cross-compiler."

The MinGW-w64 project provides good up-to-date MinGW compilers. Cygwin packages are available from within Cygwin setup. It's possible to use that compiler and SDL from libsdl.org by setting CROSS_COMPILE=i686-w64-mingw32- when running configure.

With either the old Cygwin compiler or i686-w64-mingw32-gcc, there are linking problems with multiple definitions. Those can be ignored by adding -Wl,--allow-multiple-definition to GLOBAL_LDOPTS in Makefile.

No comments: