[HowTo] Cross Compile coins with mxe | Setup mxe

Words
360
Reading
2 min
8y
Listen to this post
~2 min


Hey folks,

It is time to introduce my "HowTo" category. Today we will install and setup mxe for cross compiling coins.

Step 1: Installing mxe

As always you first of all need to install the dependencies. In the case of mxe there are many dependencies:

sudo apt-get install p7zip-full autoconf automake autopoint bash bison bzip2 cmake flex gettext git g++ gperf intltool libffi-dev libtool libltdl-dev libssl-dev libxml-parser-perl make openssl patch perl pkg-config python ruby scons sed unzip wget xz-utils

And for 64bit Ubuntu you also need:

sudo apt-get install g++-multilib libc6-dev-i386

After your done with deps, head to the directory you want to install mxe in, in my case i use /mnt so lets change the user rights for this directory:

sudo chmod ugo+rw /mnt

Done? Ok let's continue

cd /mnt
git clone https://github.com/mxe/mxe.git

Step 2: Install packages

After the last two lines your mxe installation should be placed in /mnt/mxe. Now we have to install some packages you definitly will need to compile coins. So switch to your mxe dir and lets compile:

cd /mnt/mxe
make MXE_TARGETS="i686-w64-mingw32.static" boost
make MXE_TARGETS="i686-w64-mingw32.static" qttools
make MXE_TARGETS="i686-w64-mingw32.static" qt
make MXE_TARGETS="i686-w64-mingw32.static" qt5

Nearly all coins use berkleydb and miniupnpc. Unfortunatly they are no packages included in mxe so we have to compile it ourselves:

cd /mnt
wget http://download.oracle.com/berkeley-db/db-5.3.28.tar.gz
wget http://miniupnp.free.fr/files/miniupnpc-1.6.20120509.tar.gz

When the download has finished untar each and switch into the first directory and create an new file and name it something like compile-mxe-db.sh or something else. Open it and paste ste following:

#!/bin/bash
MXE_PATH=/mnt/mxe
sed -i "s/WinIoCtl.h/winioctl.h/g" src/dbinc/win_db.h
mkdir build_mxe
cd build_mxe
CC=$MXE_PATH/usr/bin/i686-w64-mingw32.static-gcc \
CXX=$MXE_PATH/usr/bin/i686-w64-mingw32.static-g++ \
../dist/configure \
--disable-replication \
--enable-mingw \
--enable-cxx \
--host x86 \
--prefix=$MXE_PATH/usr/i686-w64-mingw32.static
make
make install

Make it executable with a right-click->permissions->Run as executable or :

chmod ugo+x compile-mxe-db.sh

and start it with:

./compile-mxe-db.sh

Repeat the last steps for miniupnpc too:

cd /mnt
tar zxvf miniupnpc-1.6.20120509.tar.gz

cd /mnt/miniupnpc-1.6.20120509
touch compile-mxe-miniupnpc.sh
chmod ugo+x compile-mxe-miniupnpc.sh

#!/bin/bash
MXE_PATH=/mnt/mxe
CC=$MXE_PATH/usr/bin/i686-w64-mingw32.static-gcc \
AR=$MXE_PATH/usr/bin/i686-w64-mingw32.static-ar \
CFLAGS="-DSTATICLIB -I$MXE_PATH/usr/i686-w64-mingw32.static/include" \
LDFLAGS="-L$MXE_PATH/usr/i686-w64-mingw32.static/lib" \
make libminiupnpc.a
mkdir $MXE_PATH/usr/i686-w64-mingw32.static/include/miniupnpc
cp *.h $MXE_PATH/usr/i686-w64-mingw32.static/include/miniupnpc
cp libminiupnpc.a $MXE_PATH/usr/i686-w64-mingw32.static/lib

./compile-mxe-miniupnpc.sh

So thats all for today. Now you should have a working mxe installation to cross-compile coins for windows under linux.

So happy coding and good night