存档:Setting up a Win32 Toolchain with SDL and wxWidgets in Gentoo
Setting up a Win32 Toolchain with SDL and wxWidgets in Gentoo
Everyone of us always wanted to have the ability to compile for Windows and Unix in one makefile, right?
Unfortunately, there is very few documentation on this topic and I had quite a hard time to get things working the way I wanted to. I wrote this small HOWTO to share the way I managed to build my toolchain to other people.
I like writing games and most gamers use Windows. I didn’t want to leave my Linux setup to compile the games for Windows, so I needed a MingW toolchain with SDL and wxWidgets, for those are the two cross platform APIs I use.
Compiling the toolchain
Here we can go with ebuilds, there are some nice in the portage tree:
emerge xmingw-binutils
emerge xmingw-gcc
emerge xmingw-w32api
emerge xmingw-runtime
emerge xmingw-gcc
You have to do it in this order and you have to compile gcc twice, yes. If you don’t you wont get a c++ compiler, i don’t know exactly why.
Gentoo will put the toolchain into /opt/xmingw.
Setting the environment variables
Everytime you want to compile something for Windows, you have to set some environment variables first. The best is to put them into a small script:
export PATH=”/opt/xmingw/bin:/opt/xmingw/i386-mingw32msvc/bin:$PATH”
export CC=”i386-mingw32msvc-gcc”
export CXX=”i386-mingw32msvc-g++”
unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LDFLAGS
export CFLAGS=”-I/opt/xmingw/i386-mingw32msvc/include”
export CXXFLAGS=”-I/opt/xmingw/i386-mingw32msvc/include”
After you have set the environment variables you can configure a program to compile for Win32 by running ./configure –target=i386-mingw32msvc –host=i386-mingw32msvc –build=i386-linux
Compiling SDL
Download the latest cvs version of SDL from here. Untar it into a working directory and cd into SDL-1.2/. Now run your script to set the environment variables mentioned above. After that you can configure SDL:
./autogen.sh
./configure –target=i386-mingw32msvc –host=i386-mingw32msvc
–build=i386-linux –enable-cdrom –enable-threads –enable-timers
–enable-endian –enable-file –enable-cpuinfo –enable-opengl
–disable-shared –prefix=/opt/xmingw/i386-mingw32msvc
–disable-shared will even remove the dependency on SDL.dll, if you don’t want that, leave this parameter out.
Now you can call make and make install. If you have to su to run make install, don’t forget to set your environment variables again (I forgot that at first).
Now for a little tweak: cd into /opt/xmingw/i386-mingw32msvc/bin and create a symbolic link.
ln -s i386-mingw32msvc-sdl-config sdl-config
This way, if you run sdl-config in your Makefile, the right sdl-config will be executed. (wxWidgets does this automatically for wx-config)
Compiling wxWidgets
Download a wxAll package from here. I used 2.4.2, I didn’t try any newer versions. Untar it and cd into wxWindows-2.4.2/.
Don’t forget to run your environment script and then run
./autogen.sh
./configure –target=i386-mingw32msvc –host=i386-mingw32msvc –build=i386-linux –with-msw –disable-threads –disable-shared –disable-unicode –with-opengl –prefix=/opt/xmingw/i386-mingw32msvc
I recommend to disable threads because else the programs will depend on some MingW libraries. You should also disable shared, because else the programs will depend on the wxWidgets libraries (and I think I ran into some more trouble). If you don’t disable unicode, the programs will only work on WinNT/2k/XP, not on 9x.
After that you can run make and make install just like you did for SDL.
Now you should have a fully working MingW+SDL+wxWidgets toolchain. I compiled 2 games I made and they ran fine in wine after compiling. I didn’t test them on Windows, yet but I strongly believe they will run. If you run into troubles, please report them to me.
Thank you for writing this tutorial. This is exactly what I’ve been searching for a long time.