Difference between revisions of "Compiling for Windows on Linux"

From The Powder Toy
Jump to: navigation, search
(Modified commands opening nautilus to use gksu/do. Always run graphical apps with gksu or kdesu!)
(updated tutorial a lot)
Line 22: Line 22:
 
'''Arch Users'''
 
'''Arch Users'''
 
In your Terminal:<br>
 
In your Terminal:<br>
<code>su -c 'pacman -S mingw32-{gcc,binutils,runtime}</code>
+
<code>su -c 'pacman -S mingw32-{gcc,binutils,runtime}'</code>
 +
 
 +
After you have installed these, in there should be /usr/iXXX-mingw32msvc , XXX may be 486, 586 or 686, but might as well be something else. Anywhere further in this tutorial i will refer to the folder name as $MINGW , for instance /usr/$MINGW/lib
 +
You might actually set such an environment variable for simplicity.
  
 
=  Libraries  =
 
=  Libraries  =
Line 35: Line 38:
 
* pthread
 
* pthread
 
* libregex (sometimes found under the name libgnurx)
 
* libregex (sometimes found under the name libgnurx)
* Lua (optional - if you don't want to use it, remove -DLUACONSOLE from the Makefile)
+
* Lua (optional - if you don't want to use it, use --nolua option)
* FFTW (optional - if you don't want to use it, remove -DGRAVFFT from the Makefile)
+
* FFTW (optional - if you don't want to use it, use --nofft option)
  
 
== Option 1: Package repositories ==
 
== Option 1: Package repositories ==
When using this method, you will usually need to distribute some DLLs to make your builds work. These are normally located in the ''bin'' folder where MinGW packages were installed (e.g. /usr/i586-mingw32msvc/bin or /usr/i686-w64-mingw32/bin).
+
When using this method, you will usually need to distribute some DLLs to make your builds work. These are normally located in /usr/$MINGW/lib
  
 
'''openSUSE users'''
 
'''openSUSE users'''
Line 53: Line 56:
 
Download the libraries (this is an incomplete list, update this wiki page if you find links for the other libraries):
 
Download the libraries (this is an incomplete list, update this wiki page if you find links for the other libraries):
  
* [http://www.libsdl.org/release/SDL-devel-1.2.14-mingw32.tar.gz SDL-devel-1.2.14-mingw32.tar.gz] from [http://www.libsdl.org/ http://www.libsdl.org/]
+
* [http://www.libsdl.org/release/SDL-devel-1.2.15-mingw32.tar.gz] from [http://www.libsdl.org/ http://www.libsdl.org/]
 
* [http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/bzip2-1.0.6-4/bzip2-1.0.6-4-mingw32-dev.tar.lzma/download bzip2-1.0.6-4-mingw32-dev.tar.lzma] from [http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/ MinGW on SourceForge].
 
* [http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/bzip2-1.0.6-4/bzip2-1.0.6-4-mingw32-dev.tar.lzma/download bzip2-1.0.6-4-mingw32-dev.tar.lzma] from [http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/ MinGW on SourceForge].
 
* [http://sourceforge.net/projects/mingw/files/Other/UserContributed/regex/mingw-regex-2.5.1/mingw-libgnurx-2.5.1-dev.tar.gz/download mingw-libgnurx-2.5.1-dev.tar.gz] from [http://sourceforge.net/projects/mingw/files/Other/UserContributed/regex/ MinGW on SourceForge]
 
* [http://sourceforge.net/projects/mingw/files/Other/UserContributed/regex/mingw-regex-2.5.1/mingw-libgnurx-2.5.1-dev.tar.gz/download mingw-libgnurx-2.5.1-dev.tar.gz] from [http://sourceforge.net/projects/mingw/files/Other/UserContributed/regex/ MinGW on SourceForge]
 +
* [ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip] from [http://sourceware.org/pthreads-win32/]
  
 
===  Extract  ===
 
===  Extract  ===
'''THE EXTRACTION PROCESS CAN ONLY BE DONE AS ROOT USER. USE AN ALTERNATE WORKSPACE AND CLOSE ALL WINDOWS WHEN FINISHED.'''
 
 
GNOME:
 
<code>gksudo nautilus
 
-OR-
 
gksu -w nautilus</code>\\
 
XFCE use Thunar instead of Nautilus\\
 
KDE use Konqueror and kdesudo instead of gksudo.
 
 
The target folder for all extractions is /usr/i586-mingw32msvc (Arch use /usr/i486-mingw32). Everything I'm telling you to extract is a folder and any overwrites or merges should be permitted.
 
 
====  SDL-devel-1.2.14-mingw32.tar.gz  ====
 
Extract the bin, include and libs folders
 
 
====  bzip2-1.0.6-4-mingw32-dev.tar.lzma  ====
 
Extract the entire archive.
 
  
====  mingw-libgnurx-2.5.1-dev.tar.gz  ====
+
This needs root.
Extract the entire archive.
 
  
===  DLLs  ===
+
All of these archives have subdirectories called include/ , lib/ and bin/
These DLLs will need to be distributed with your builds so they work. Or if you're lazy you can just  post the URLs and tell everyone else to download them.
 
  
* http://tinyurl.com/sdldll - SDL.dll
+
Simply copy all files from include/ into /usr/$MINGW/include/ , then all .a files from lib/ into /usr/$MINGW/lib/ , and all .dll from bin/ into folder where your executable will be.
* http://tinyurl.com/bz2dll - libbz2-2.dll
 
* http://tinyurl.com/grxdll - libgnurx-0.dll
 
  
 +
Only exception is pthreads, it is basically the same, except that in the beginning you have to go into Pre-built.2/ , and both lib/ and bin/ have x64/ and x86/ subfolders, since we're compiling for x86 you obviously need that one.
  
 
== Option 3: Building from source ==
 
== Option 3: Building from source ==
 
This is the method to use if you want to use static linking (so that the executable does not need extra DLL files to run).  
 
This is the method to use if you want to use static linking (so that the executable does not need extra DLL files to run).  
  
Since figuring out all the right commands to cross compile the libraries can be difficult, here is a script that (hopefully) has all the right commands already: https://raw.github.com/jacksonmj/The-Powder-Toy/master/powder-cross-libs.sh
+
Since figuring out all the right commands to cross compile the libraries can be difficult, here is a script that (hopefully; update: it does not :C) has all the right commands already: https://raw.github.com/jacksonmj/The-Powder-Toy/master/powder-cross-libs.sh
  
 
Running the script without arguments provides usage instructions. Start by changing the variables at the start of the script to match your MinGW installation. Then compile and install the libraries as follows (they will automatically be downloaded):
 
Running the script without arguments provides usage instructions. Start by changing the variables at the start of the script to match your MinGW installation. Then compile and install the libraries as follows (they will automatically be downloaded):
Line 98: Line 83:
  
 
=  Compile  =
 
=  Compile  =
Some Makefile changes may be needed.
+
Some SConscript changes may be needed.
 +
 
 +
It should be as simple as
 +
<code>scons --win --tool=$MINGW-</code>
 +
Notice the dash, if for you $MINGW is i586-mingw32msvc you should pass --tool=i586-mingw32msvc-
 +
 
 +
If you have problems with initial libraries lookup, it is useful to check config.log for obvious failures.
 +
 
 +
If when linking it gives you an error like
  
CC_WIN and WIN_RES should be set to the names of the relevant MinGW programs. These names vary between distributions.
+
<code>/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/libstdc++.a(stubs.o):(.text+0x540): multiple definition of `_coshf'
  
Arch users:
+
build/src/Misc.o:Misc.cpp:(.text$coshf[_coshf]+0x0): first defined here</code>
  
<code>CC_WIN := i486-mingw32-gcc<br>
+
do this (under root):
WIN_RES := i486-mingw32-windres</code>
 
  
Change all instances of ''-llibregex'' to ''-llibgnurx''
+
<code>cd /usr/lib/gcc/$MINGW/4.2.1-sjlj/
  
Save, Exit, cd to your powder toy directory and run:
+
$MINGW-ar -d libstdc++.a stubs.o</code>
<code>make powder-sse.exe powder-sse2.exe powder-sse3.exe</code>
 
  
 +
If this tutorial has any obvious (and not very obvious) failures, feel free to edit.
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Compiling]]
 
[[Category:Compiling]]

Revision as of 17:26, 18 May 2013

This is for Linux users to cross-compile to Windows 32-bit.

BEFORE WE START, PLEASE MAKE SURE YOU CAN COMPILE FOR LINUX FIRST!

Packages

First, install the basic packages needed for cross compiling.

Search for the following in your package manager: mingw32 mingw32-binutils mingw32-runtime

Ubuntu Users Copy and paste this into your address bar (Firefox):
apt:mingw32,mingw32-binutils,mingw32-runtime"

If it doesn't work, use the following in a terminal:
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime

Debian Users In a terminal:
su -c "apt-get install mingw32 mingw32-binutils mingw32-runtime"

Arch Users In your Terminal:
su -c 'pacman -S mingw32-{gcc,binutils,runtime}'

After you have installed these, in there should be /usr/iXXX-mingw32msvc , XXX may be 486, 586 or 686, but might as well be something else. Anywhere further in this tutorial i will refer to the folder name as $MINGW , for instance /usr/$MINGW/lib You might actually set such an environment variable for simplicity.

Libraries

Next, Powder Toy needs a couple of libraries. There are three ways to get them:

  • Package repositories. This is usually the easiest way, but not all distributions have MinGW versions of all the required libraries in their package repositories
  • Download and extract precompiled libraries. However, this wiki page does not currently have links for all the libraries.
  • Compile from source. This can be difficult, but there is a script available to help you. You'll need to use this method if you don't want to distribute DLL files with your executables.

The libraries needed are:

  • SDL
  • bzip2
  • pthread
  • libregex (sometimes found under the name libgnurx)
  • Lua (optional - if you don't want to use it, use --nolua option)
  • FFTW (optional - if you don't want to use it, use --nofft option)

Option 1: Package repositories

When using this method, you will usually need to distribute some DLLs to make your builds work. These are normally located in /usr/$MINGW/lib

openSUSE users

Some of the required libraries can be found here: https://build.opensuse.org/project/show?project=windows%3Amingw%3Awin32

Repository URL for package manager: http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_11.4/

Option 2: Precompiled

Download

Download the libraries (this is an incomplete list, update this wiki page if you find links for the other libraries):

Extract

This needs root.

All of these archives have subdirectories called include/ , lib/ and bin/

Simply copy all files from include/ into /usr/$MINGW/include/ , then all .a files from lib/ into /usr/$MINGW/lib/ , and all .dll from bin/ into folder where your executable will be.

Only exception is pthreads, it is basically the same, except that in the beginning you have to go into Pre-built.2/ , and both lib/ and bin/ have x64/ and x86/ subfolders, since we're compiling for x86 you obviously need that one.

Option 3: Building from source

This is the method to use if you want to use static linking (so that the executable does not need extra DLL files to run).

Since figuring out all the right commands to cross compile the libraries can be difficult, here is a script that (hopefully; update: it does not :C) has all the right commands already: https://raw.github.com/jacksonmj/The-Powder-Toy/master/powder-cross-libs.sh

Running the script without arguments provides usage instructions. Start by changing the variables at the start of the script to match your MinGW installation. Then compile and install the libraries as follows (they will automatically be downloaded):

./powder-cross-libs.sh make bzip2 fftw lua pthread regex sdl

sudo ./powder-cross-libs.sh install bzip2 fftw lua pthread regex sdl

Compile

Some SConscript changes may be needed.

It should be as simple as scons --win --tool=$MINGW- Notice the dash, if for you $MINGW is i586-mingw32msvc you should pass --tool=i586-mingw32msvc-

If you have problems with initial libraries lookup, it is useful to check config.log for obvious failures.

If when linking it gives you an error like

/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/libstdc++.a(stubs.o):(.text+0x540): multiple definition of `_coshf'

build/src/Misc.o:Misc.cpp:(.text$coshf[_coshf]+0x0): first defined here

do this (under root):

cd /usr/lib/gcc/$MINGW/4.2.1-sjlj/

$MINGW-ar -d libstdc++.a stubs.o

If this tutorial has any obvious (and not very obvious) failures, feel free to edit.