[HowTo] CrossCompiling wallets with mxe. New HowTo

in pxlfusseltec •  4 years ago  (edited)

Hey whats up,

After a short break on steemit, still trying get my old account back, i decided to use this account from now on.
And the first bigger post i want to write is a rewrite of my old post How to cross compile with mxe.

So let's get started.
First of all i am working with Ubuntu 20.10 at the moment. So if you work with another version or distribution
you need to install the dependencies on your way.

Preparing the path

I really recommend to use the /mnt folder in the linux root for installing mxe! It make things easier to follow this [HowTo].
If you are an experienced Linux user, feel free to install where ever you want.

Ok so first thing we do is to make /mnt writeable for you.

cd /
sudo chmod ugo+rw mnt
cd mnt

Checkout mxe and prepare a recipe

Now we are in the mnt folder and checkout the mxe repo from github. If you don't have git installed just do:

sudo apt install git

After that you can checkout the repo with:

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

Ok now we need to prepare a recipe of mxe, that we don't run into issues when compiling wallets. Just open the qtbase.mk file in the src folder and delete the line -openssl-linked \

gedit src/qtbase.mk

Like this:
openssl-linked1.png
into:
openssl-linked2.png
Save and exit gedit.

Install dependencies

Before we start installing the dependencies for wallet compilation, we need to install the dependencies for installing things in mxe environment:

sudo apt install autoconf automake autopoint bash bison bzip2 flex g++ g++-multilib gettext git gperf intltool libc6-dev-i386 libgdk-pixbuf2.0-dev libltdl-dev libssl-dev libtool-bin ibxml-parser-perl lzip make openssl p7zip-full patch perl python ruby sed unzip wget xz-utils

Ok now it is time to install the first dependencies for wallets libboost, qttools and qt5. Please have a seat, take enough coffee and some snacks when you want to stay, because it takes a little till it those three are installed.
Ready? Ok let's start!
Feel free to build only what you need, i will build both 32-bit and 64-bit:

make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' boost
make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' qttools
make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' qt5

This really takes a long time. If you want to do it over night you can also do:

make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static'

to build all mxe packages.
When it is finished over all, it is ready to use.

Additional work for wallets (dependencies) =D

For compiling the wallets we need to download BerkeleyDB and miniupnpc if we want to support it. Just create a folder in /mnt for all dependencies:

cd /mnt
mkdir deps

After that we went into the folder and download these those two archives:

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

So now we want to use them with mxe, we need to compile them with mxe. So make sure your mxe installation is ready and working!

Now we decompress and rename their folders for better usage in the .pro file of the wallet:

tar xvzf db-5.3.28.tar.gz
mv db-5.3.28 bdb
tar xvzf miniupnpc-1.6.20120509.tar.gz
mv miniupnpc-1.6.20120509.tar.gz miniupnpc

At this point we can start to compile them.

The first compile with mxe

Ok let's do some work. We now went in each folder and write a little compile-script to make things easier. Also for the windows build of bdb we need to change a line in the code:

cd bdb
gedit compile.sh

With the last command the linux texteditor gedit starts with a blank window and a the given filename compile.sh, so all we need to do is paste this code in it and save it:

#!/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

So this script searches in the win_db.h the the given parameter and replace it with lower-case writing. That is important because it will crash the compile, if we don't change the line.
Now make the script executable and run it with

chmod ugo+x compile.sh
./compile.sh

Now you can see it compiling and installing in the mxe folder. The nearly same we will do with miniupnpc:

cd /mnt/deps/miniupnpc
gedit compile.sh

and paste:

#!/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

And again, save it, make it executable and run it.

Closing words

Ok thank you keep reading till here and a big respect if you did all those things for the first time. When i first set up a mxe environment it struggled around with it a whole weekend.
On the next post i will show you how to compile a coin wallet with it.
If you run into errors feel free to ping me on discord PXLFuSSeL#7688

So happy coding and good bye till then!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!