User avatar
amaipaipai
Posts: 9
Joined: Fri Jul 21, 2017 11:16 am

Compiling MAME Windows binary on a Debian Linux

This is a small description on how to compile a windows binary on a Linux machine. (cross-compiling)
To compile mame binary over windows it's time consuming, on my machine it takes about 2:48 hours to compile the 0.189 source code with make -j16.

Code: Select all

Windows 10 64 Bit 1703 (15063.608)
GIGABYTE AM3+ ATX GA-990FXA-UD5 R5
AMD FX-8350 Vishera
Corsair Vengeance 16GB (2x8GB) 1866MHz DDR3 CL10 Red CMZ16GX3M2A1866C10R
This is the TimeMem info:

Code: Select all

Linking mame64.exe...
Exit code      : 0
Elapsed time   : 8944.14
Kernel time    : 12.86 (0.1%)
User time      : 2.28 (0.0%)
page fault #   : 8360
Working set    : 18768 KB
Paged pool     : 100 KB
Non-paged pool : 8 KB
Page file size : 14776 KB
8944/3600 = 2:48hrs

Over Linux is a different story, compiling the exact same source with the same computer, with the same "make -j16" it takes only 24 minutes:

Code: Select all

Linking mame64.exe...
real	24m4,513s
user	157m24,328s
sys	10m5,328s
I'm using Debian 9.1 (Stretch) and this is what you have to do:
1. Download the tools, this will install all the necessary software and aptitude will handle the rest.

Code: Select all

sudo aptitude install git build-essential libsdl2-dev libsdl2-ttf-dev libfontconfig-dev qt5-default binutils-mingw-w64-x86-64 g++-mingw-w64 g++-mingw-w64-x86-64 gcc-mingw-w64 gcc-mingw-w64-base gcc-mingw-w64-x86-64 gobjc++-mingw-w64 mingw-w64 mingw-w64-common mingw-w64-tools mingw-w64-x86-64-dev win-iconv-mingw-w64-dev
2. Now you need to put the correct "gcc, ar, and g++" at the right place, failing to do this will return a bunch of errors, use the posix versions.

Code: Select all

sudo ln -s /usr/bin/x86_64-w64-mingw32-g++-posix /usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-g++
sudo ln -s /usr/bin/x86_64-w64-mingw32-gcc-ar-posix /usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc-ar
sudo ln -s /usr/bin/x86_64-w64-mingw32-gcc-posix /usr/x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc
3. Set the MINGW64 variable with:

Code: Select all

export MINGW64="/usr/x86_64-w64-mingw32"
You can add this to your $PATH in your .bashrc

Code: Select all

echo "export MINGW64="/usr/x86_64-w64-mingw32"" >> ~/.bashrc
4. Compile with:

Code: Select all

make clean && make REGENIE=1 TARGETOS=windows CROSS_BUILD=1 OPTIMIZE=3 SSE2=1 PTR64=1
That's it.
This should work with other Linux distro. Don't forget to do the following command at the end:

Code: Select all

strip mame64.exe
If the compilation end up in a error about missing a #include file or something like that, is because you are using the wrong gcc or g++ with the correct one, it will find the files needed.

Good luck.
Last edited by amaipaipai on Mon Apr 02, 2018 1:44 am, edited 3 times in total.
User avatar
amaipaipai
Posts: 9
Joined: Fri Jul 21, 2017 11:16 am

Re: Compiling MAME Windows binary on a Debian Linux

Settings for cross compiling a x32 version, once the x64 are in place, just follow the instructions bellow.

Code: Select all

sudo ln -s /usr/bin/i686-w64-mingw32-g++-posix /usr/i686-w64-mingw32/bin/i686-w64-mingw32-g++
sudo ln -s /usr/bin/i686-w64-mingw32-gcc-ar-posix /usr/i686-w64-mingw32/bin/i686-w64-mingw32-gcc-ar
sudo ln -s /usr/bin/i686-w64-mingw32-gcc-6.3-posix /usr/i686-w64-mingw32/bin/i686-w64-mingw32-gcc

Code: Select all

export MINGW32="/usr/i686-w64-mingw32"
Or set it at your .bashrc

Code: Select all

echo "export MINGW32="/usr/i686-w64-mingw32"" >> ~/.bashrc
Than:

Code: Select all

make clean && make REGINIE=1 TARGETOS=windows CROSS_BUILD=1 OPTIMIZE=3 SSE2=1
Done.

Return to “MAME Discussion”