Cross Compile with MinGW

Versione italiana Developer corner



Rocrail cross compiled on Ubuntu for Windows – Cross compiling for Windows from an Ubuntu computer is a bit challenging. You must compile Rocrail for Ubuntu before you try to cross compile for Windows.

You will need to install several tools and packages before you can cross compile. Make sure they are installed and working properly before you try to cross compile.

The important tools that you must have are:

  • MinGW32, a cross-compiler for creating windows executables when compiling under Linux
  • wxAll sources for wxWidgets, the full set of wxWidgets source code that includes windows versions
  • Wine, a shell system that will run windows executables under Linux
  • Inno Setup, a free windows installer creation program that runs under windows

Perform the next steps carefully and in sequence to create a windows installer version of Rocrail.

get the cross compiler:

sudo apt-get install mingw32

GdiPlus

If GdiPlus is missing: (and it usually is)

Copy the contents to /usr/i586-mingw32msvc:

unzip gdiplus.zip
cd gdiplus
sudo cp -r include/* /usr/i586-mingw32msvc/include/
sudo cp -r lib/* /usr/i586-mingw32msvc/lib/

get wxWidgets

tar xvjf wxWidgets-3.0.1.tar.bz2
cd wxWidgets-3.0.1
# run configure like:

./configure --prefix=/usr/i586-mingw32msvc --host=i586-mingw32msvc --target=i586-mingw32msvc --with-msw --enable-unicode --enable-mslu --disable-shared --enable-graphics_ctx --enable-monolithic 

make the wx libraries:

make

install it:

sudo make install

build the rocrail modules:

cd Rocrail
cd rocs
make PLATFORM=WIN32 clean
make TOOLPREFIX=i586-mingw32msvc- PLATFORM=WIN32 all
cd ../rocint
make PLATFORM=WIN32 clean
make TOOLPREFIX=i586-mingw32msvc- PLATFORM=WIN32 all
cd ../rocrail
make PLATFORM=WIN32 clean
make TOOLPREFIX=i586-mingw32msvc- PLATFORM=WIN32 all
cd ../roclcdr
make PLATFORM=WIN32 clean
make TOOLPREFIX=i586-mingw32msvc- PLATFORM=WIN32 all
cd ../rocdigs
make PLATFORM=WIN32 clean
make TOOLPREFIX=i586-mingw32msvc- PLATFORM=WIN32 all
cd ..

build the UNICODE rocview: (using the common makefile)

cd rocview
make PLATFORM=WIN32 clean
make TOOLPREFIX=i586-mingw32msvc- LIBSUFFIX=-i586-mingw32msvc PLATFORM=WIN32 MINGWINSTALL=/usr/i586-mingw32msvc all
cd ..

#note: The 'i586-mingw32msvc' text must be according to your installation of mingw, change when needed.

build all modules from the Rocrail main makefile:

make all PLATFORM=WIN32 TOOLPREFIX=i586-mingw32msvc- LIBSUFFIX=-i586-mingw32msvc MINGWINSTALL=/usr/i586-mingw32msvc

see also: http://www.wxwidgets.org/wiki/index.php/Cross-Compiling_Under_Linux

strip the binaries

cd winbin
i586-mingw32msvc-strip *.dll
i586-mingw32msvc-strip *.exe
cd ..

copy mingw runtime dll to winbin directory

Extract /usr/share/doc/mingw32-runtime/mingwm10.dll.gz to winbin

cd winbin
sudo gunzip /usr/share/doc/mingw32-runtime/mingwm10.dll.gz
cp /usr/share/doc/mingw32-runtime/mingwm10.dll .
cd ..

run inno setup with wine and create the package

Get and install wine from the official Wine HQ site Wine Headquarters or as distribution package:

sudo apt-get install wine

Get and install the Inno Setup windows exe using wine from the official Inno Setup site:

Inno Setup Website
#note: if you want to use the distribution scripts: the installation path has to be exactly “c:\Program Files\Inno Setup 5”

Create the package by changing to the rocrail directory and running Inno Setup with the rocrail.iss file (see makwin-full.sh on how to generate setup.iss from rocrail-template.iss) :

cd rocrail/package
wine "c:\\Program Files\\Inno Setup 5\\ISCC.exe" rocrail.iss
cd ../..

Cross compile with mingw-i686-w64 for Windows 32

To cross compile using the 32/64 bits mingw compiler you first need to get the following packages, using your favourite package manager:

gcc-mingw-w64-base
gcc-mingw-w64-i686
mingw-w64-dev
binutils-mingw-w64-i686
g++mingw-w64-i686

If mingw32 was installed, the package manager will want to remove it because it is conflicting. Allow this.

First, wxWidgets have to be configured for use with mingw-w64-i686. If you do not have the wxWidgets yet, get the wxAll and extract the files as per the instructions above. Use the following command to configure the make files for the wxWidgets, from a terminal in the wxWidgets directory:

./configure --prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32 --target=i686-w64-mingw32 --with-msw --enable-unicode --enable-mslu --disable-shared --enable-graphics_ctx LDFLAGS=-static --enable-monolithic 

The LDFLAGS=-static will include the required dll files during linking. With this flag it is not needed to copy needed dll files manually to the Rocrail/Rocview directory.

Now build and install the wx libraries:

make

sudo make install

Rocrail and Rocview can be cross compiled using the main makefile (updated for mingw-w64-i686 at revision 3823) using the command:

make all PLATFORM=WIN32 TOOLPREFIX=i686-w64-mingw32- LIBSUFFIX=-i686-w64-mingw32 MINGWINSTALL=/usr/i686-w64-mingw32

The binaries in the winbin directory need to be stripped and the mingw10.dll added in the usual way as described above.


Personal Tools