Monday 30 May 2011

A working setup

I appear to have cracked getting Codeblocks to create code that will run on both a Linux environment and Windows. The same project can be used to generate an OSX version of the application, although has to be separately created on my macBook.

The only extra bit would be to get the code to cross-compile and run under OSX from within Linux (the cherry on my cupcake).

The OSX build
This will only work (for the moment) natively using codeblocks.

  • Add new build targets OSXDebug and OSXRelease based on the default Debug and Release setups.
  • Change the compiler and linker to include the -arch i386
  • In the post-build steps add the following

mkdir -p $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).app/Contents/MacOS/
/Developer/Tools/SetFile -t APPL $(TARGET_OUTPUT_FILE)
/Developer/Tools/Rez -d __DARWIN__ -t APPL Carbon.r -o $(TARGET_OUTPUT_FILE)
cp $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).app/Contents/MacOS/$(TARGET_OUTPUT_BASENAME)
/usr/local/bin/dylibbundler -od -b -x $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).app/Contents/MacOS/$(TARGET_OUTPUT_BASENAME) -d ./$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).app/Contents/libs/

For Windows
Install the mingw cross-compiler
Download and compile a mingw windows version of the wxwidgets libraries. This took a while...

Go to Settings, Compiler and Debugger settings. Add a new compiler based on the gcc one. Change the toolchain executables to point to the mingw executables.

Add new build targets WinDebug and WinRelease.
Change the compiler to the mingw one.
Make sure you have included the .exe extension for output filename.
Change the wx-config to point to the version you have compiled.

Other foibles for the Windows cross-compile
Certain libraries may be needed for the executable to run on the windows machine.

In the post build steps, add the following
cp /usr/share/doc/mingw32-runtime/mingwm10.dll $(TARGET_OUTPUT_DIR)
cp /usr/local/i586-mingw32/lib/wxbase28_gcc_custom.dll $(TARGET_OUTPUT_DIR)
cp /usr/local/i586-mingw32/lib/wxmsw28_core_gcc_custom.dll $(TARGET_OUTPUT_DIR)
cp /usr/local/i586-mingw32/lib/libwx_base-2.8*a $(TARGET_OUTPUT_DIR)
cp /usr/local/i586-mingw32/lib/libwx_msw_core*a $(TARGET_OUTPUT_DIR)

What next?
  • Having the compiler automatically generate an install routine for the windows (mainly to put the dll's into the windows system folder)
  • Getting the Linux build to cross-compile for the OSX platform
  • Writing an application that works across all three platforms

I'm not sure which of the three would be the easiest...

No comments:

Post a Comment