Finally got the whole thing to build! ^o^ Had to reverse engineer configure scripts and makefiles like crazy (Google couldn't have been more helpless), but I figured it out after all. Going to post here what I did in the end. Note: this is for 32-bit Windows, for 64-bit Windows replace i686-w64-mingw32 with x86_64-w64-mingw32 (should be the same for everything else otherwise). Also I'm making the code not use the shared libgcc (in fact it seems the DLL is not present in my system...).
First of all, for the configure-based libraries (except zlib - so SDL2, libogg, libvorbis), this will do:
./configure --build=x86_64-linux-gnu --host=i686-w64-mingw32 --prefix=/usr/local/cross-tools/i686-w64-mingw32 --disable-shared
sudo make install
This alone won't work with libvorbis since it'll try to link to libogg from a different path (and will end up trying to link to the Linux libogg by default, whoops!). We have to override this by setting these variables before doing the steps above:
export OGG_LDFLAGS="-L/usr/local/cross-tools/i686-w64-mingw32/lib -logg"
Then let's go for zlib, which handles Windows in an unique way (and isn't that crosscompile friendly anyway). You will need to do this:
cp win32/Makefile.gcc Makefile
sudo make install DESTDIR=/usr/local/cross-tools/i686-w64-mingw32
Now for the CMake-based libraries (PhysicsFS, libpng). First we need a file with the following:
Then we can proceed to build by doing the following (replace ~/wincmake.cmake with whatever is the filename of that file I just mentioned):
cmake -DCMAKE_TOOLCHAIN_FILE=~/wincmake.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/cross-tools/i686-w64-mingw32 -DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc ..
sudo make install
Note that the above won't be enough with libpng (I built libpng with cmake since I was making a script and it autodetected cmake for it). You will need to add the following to the cmake line for libpng:
Now to set up Code::Blocks. Go to the compiler settings and make a copy of the GCC compiler (give it whatever name you want, I just appended "(Windows)" to the name). Then go to the search directories path. In the Compiler and Resource compiler tabs (yeah, do the same on both), add this:
In the Linker tab, add this:
Then go to the toolchain executables tab and prepend i686-w64-mingw32- to every executable except make, and set the resource compiler to i686-w64-mingw32-windres. No, you shouldn't change the directory, the MinGW-w64 executables get installed to /usr/bin like the rest of the programs.
That's all. Now go make a new Code::Blocks project that's identical to your Linux one but you choose the Windows compiler instead. Add -static-libgcc to the compiler options, and in the build target tabs in the project properties make sure to choose different paths (e.g. wobj/ instead of obj/). Finally, make sure to append .exe to the executable filenames (disable "auto-generate filename extension" or Code::Blocks will get rid of it). Now build! ^o^
- As you can imagine, the program will want to use the DLLs of the libraries. They're located in /usr/local/cross-tools/i686-w64-mingw32/bin, just retrieve them from there and put them in the directory where the EXE resides.
- If you want to make sure the generated executable is indeed a Windows one, use the file command. It should say something along the lines of "PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows". If it says ELF, you built a Linux executable instead and you should recheck the Code::Blocks settings.
- When I tried running the game under Wine it crashed in the most epic way possible. It runs flawlessly on the real thing though. Seems like the way SDL2 initializes the audio is making Wine fail horribly. So yeah, don't expect being able to test SDL2 Windows programs on Wine.
EDIT: "linker tag"? (lol typo)
Edited by Sik_the_hedgehog, 04 August 2014 - 12:10 AM.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.