Difference between revisions of "Compiling for Windows on Linux"
(Edit link to cross-libs.sh, direct to updated version hosted on github) |
(Update to reflect updated script and new/upgraded dependencies) |
||
Line 43: | Line 43: | ||
By compiling all the libraries yourself, the final executable will not need any DLLs to run. | By compiling all the libraries yourself, the final executable will not need any DLLs to run. | ||
− | Since figuring out all the right commands to cross compile the libraries can be difficult, here is a script that has all the right commands already: [https:// | + | Since figuring out all the right commands to cross compile the libraries can be difficult, here is a script that has all the right commands already: [https://git.starcatcher.us/jacob1/buildserver-snapshot/raw/branch/master/provisioning-files/cross-libs/cross-libs.sh 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. The default values are:<br /> | Running the script without arguments provides usage instructions. Start by changing the variables at the start of the script to match your MinGW installation. The default values are:<br /> | ||
Line 58: | Line 58: | ||
Now compile and install the libraries as follows (they will automatically be downloaded. Simply open a terminal, and enter the following commands): | Now compile and install the libraries as follows (they will automatically be downloaded. Simply open a terminal, and enter the following commands): | ||
− | <code>./cross-libs.sh make bzip2 fftw lua pthread regex | + | <code>./cross-libs.sh make bzip2 fftw lua pthread regex sdl2 zlib curl</code> |
− | <code>sudo ./cross-libs.sh install bzip2 fftw lua pthread regex | + | <code>sudo ./cross-libs.sh install bzip2 fftw lua pthread regex sdl2 zlib curl</code> |
If the script doesn't run, you need to allow the file to be run as an executable. To do this, use <code>chmod +x cross-libs.sh</code> | If the script doesn't run, you need to allow the file to be run as an executable. To do this, use <code>chmod +x cross-libs.sh</code> |
Revision as of 23:28, 2 March 2020
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
Run the following in a terminal:
sudo apt-get install mingw-w64
In older recent versions of Ubuntu, try:
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, there should be /usr/XXXX-mingw32msvc , XXXX may be i486, i586, i686 or something else. Anywhere further in this tutorial i will refer to the folder name as $MINGW , for instance /usr/$MINGW/lib You could 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 sometimes 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, you usually cannot statically compile when using this way
- Compile from source. This would normally 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
- 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)
Compiling Libraries
By compiling all the libraries yourself, the final executable will not need any DLLs to run.
Since figuring out all the right commands to cross compile the libraries can be difficult, here is a script that has all the right commands already: 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. The default values are:
HOST="i686-w64-mingw32" MINGW_BIN_PREFIX="i686-w64-mingw32-" MINGW_INSTALL_DIR="/usr/i686-w64-mingw32"
On older versions of Debian/Ubuntu, you might change this to:
HOST="i586-mingw32msvc" MINGW_BIN_PREFIX="i586-mingw32msvc-" MINGW_INSTALL_DIR="/usr/i586-mingw32msvc"
Please note, if you installed MingW for older recent versions of Ubuntu as shown in step 1, you MUST change these variables.
Now compile and install the libraries as follows (they will automatically be downloaded. Simply open a terminal, and enter the following commands):
./cross-libs.sh make bzip2 fftw lua pthread regex sdl2 zlib curl
sudo ./cross-libs.sh install bzip2 fftw lua pthread regex sdl2 zlib curl
If the script doesn't run, you need to allow the file to be run as an executable. To do this, use chmod +x cross-libs.sh
Compile
It should be as simple as
scons --win
Some SConscript changes may be needed if the name of your cross compiler isn't standard (or just not listed in the SConscript). If it does not detect your cross compiler, try using:
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.