Compiling a Win32 Binary on Linux
by Steven Campbell · in Technical Issues · 09/09/2005 (8:57 am) · 5 replies
Ok here's a rather quick and dirty tutorial on how to do this..
I found the scripts that I originally used to set up my environment, so I'm sharing that all with you here :)
They were a bugger for me to find, so hopefully this'll help a few people here... anyway let's start...
DISCLAIMER
This is not the be-all and end-all of how to do this.. there's probably a hellova lot of methods of doing this, this is just the way I did it. This may or may not work, I am using Gentoo Linux and I have my system set up EXACTLY how I like so what follows may not be what you have... with that out the way, let's begin ;)
STEP ONE
Firstly you'll need this thing: XBuild.sh it's a script that will build the entire toolchain needed.. it's using i586-mingw32. This was found after trawling the net for help to set this up myself, and since it wasn't exactly easy to find, here it is for everyone else who was in the same pickle I was.
Save that file in a temp folder (/tmp will do :) ) and become root. Run the script ( sh ./xbuild.sh ) then go have something to eat cause it will take a while. Once it's done, you've a basic setup to create C/C++ programs for Windows!
Don't believe me? do a simple hello world program then make a script with this mess in it:
Run the script and you'll get helloworld.exe spat out, and running that in WINE will show you that it is indeed working. If not, then something may have gone wonky, so post any and all error messages if you didn't get this far.
STEP TWO -- optional really
Surprisingly, that's all you actually need.. the build script above has included all the D3D and GL stuff you should require.. however, what if you want to add other libraries? For example, SDL? Well that's reasonably straight forward, just remember that you're basically using MinGW32 now.. so if any library has an option for that.. you download that package, if it doesn't, it usually has options to be run through MinGW32 so make sure you check them first before compiling.. always read the INSTALL files if available and have a quick nosey at the MAKEFILEs to see if there's any options you can change... as you don't want to end up creating Linux/Windows hybrid nonsense that won't work on either O/S (as I've erm.. done before *cough* hehe).
Here's a default make script that you may want to use.. basically after you've sorted your MAKEFILEs and made sure whatever libs you're installing are gonna behave themselves and use any MinGW32 specific options/code it may have, just run this and you're done. XMake.sh - which is mostly the same as the script above for the hello world program, but ends with exec make $* so it parses the MAKEFILE.
Continued below... hehe
I found the scripts that I originally used to set up my environment, so I'm sharing that all with you here :)
They were a bugger for me to find, so hopefully this'll help a few people here... anyway let's start...
DISCLAIMER
This is not the be-all and end-all of how to do this.. there's probably a hellova lot of methods of doing this, this is just the way I did it. This may or may not work, I am using Gentoo Linux and I have my system set up EXACTLY how I like so what follows may not be what you have... with that out the way, let's begin ;)
STEP ONE
Firstly you'll need this thing: XBuild.sh it's a script that will build the entire toolchain needed.. it's using i586-mingw32. This was found after trawling the net for help to set this up myself, and since it wasn't exactly easy to find, here it is for everyone else who was in the same pickle I was.
Save that file in a temp folder (/tmp will do :) ) and become root. Run the script ( sh ./xbuild.sh ) then go have something to eat cause it will take a while. Once it's done, you've a basic setup to create C/C++ programs for Windows!
Don't believe me? do a simple hello world program then make a script with this mess in it:
#!/bin/sh PREFIX=/opt/Code/win32tools TARGET=i586-mingw32msvc PATH="$PREFIX/bin:$PREFIX/$TARGET/bin:$PATH" export PATH gcc -o helloworld.exe helloworld.c
Run the script and you'll get helloworld.exe spat out, and running that in WINE will show you that it is indeed working. If not, then something may have gone wonky, so post any and all error messages if you didn't get this far.
STEP TWO -- optional really
Surprisingly, that's all you actually need.. the build script above has included all the D3D and GL stuff you should require.. however, what if you want to add other libraries? For example, SDL? Well that's reasonably straight forward, just remember that you're basically using MinGW32 now.. so if any library has an option for that.. you download that package, if it doesn't, it usually has options to be run through MinGW32 so make sure you check them first before compiling.. always read the INSTALL files if available and have a quick nosey at the MAKEFILEs to see if there's any options you can change... as you don't want to end up creating Linux/Windows hybrid nonsense that won't work on either O/S (as I've erm.. done before *cough* hehe).
Here's a default make script that you may want to use.. basically after you've sorted your MAKEFILEs and made sure whatever libs you're installing are gonna behave themselves and use any MinGW32 specific options/code it may have, just run this and you're done. XMake.sh - which is mostly the same as the script above for the hello world program, but ends with exec make $* so it parses the MAKEFILE.
Continued below... hehe
#2
I got Error 404 while trying to get http://www.stuckieworld.net/public/xbuild.sh / http://www.stuckieworld.net/public/xmake.sh
05/06/2006 (10:47 pm)
Welcome,I got Error 404 while trying to get http://www.stuckieworld.net/public/xbuild.sh / http://www.stuckieworld.net/public/xmake.sh
#3
Here's the new home:
www.stuckieworld.net/files/coding/cross/xmake.sh
www.stuckieworld.net/files/coding/cross/xbuild.sh
Surprised no-one mentioned sooner, cause I forgot about them *cough* oops
They are quite old now, so I don't know if they still work, but I'm sure they will with a few changes :)
Again, sorry for that, I forgot to re-upload after the site went bad.
Take Care,
Steven -=STUCKIE=- Campbell
05/07/2006 (5:06 am)
Ooo, sorry about that... the site suffered a crash a while ago and I forgot to re-upload them.Here's the new home:
www.stuckieworld.net/files/coding/cross/xmake.sh
www.stuckieworld.net/files/coding/cross/xbuild.sh
Surprised no-one mentioned sooner, cause I forgot about them *cough* oops
They are quite old now, so I don't know if they still work, but I'm sure they will with a few changes :)
Again, sorry for that, I forgot to re-upload after the site went bad.
Take Care,
Steven -=STUCKIE=- Campbell
#4
05/07/2006 (5:21 am)
You should post this as a resource, It's pretty useful information.
#5
It would've probably been done sooner, but I got sidetracked with university coursework, and with an exam on Thursday, I'm not out of the waters yet.
However, I've noted it down on my list of things to-do, so I'll get there, this time :)
Take Care,
Steven -=STUCKIE=- Campbell
05/07/2006 (5:27 am)
I think I'll check it first to make sure it does compile the latest versions, and works properly, before figuring out how to do that ;)It would've probably been done sooner, but I got sidetracked with university coursework, and with an exam on Thursday, I'm not out of the waters yet.
However, I've noted it down on my list of things to-do, so I'll get there, this time :)
Take Care,
Steven -=STUCKIE=- Campbell
Torque Owner Steven Campbell
Arcade Badgers
Now to get Torque up and running... download the LINUX SDK again, and install it into another folder, I shoved it in /home/stuckie/Coding/Tools/TorqueWIN32.
You'll want to set it up to be Win32 and use GCC3.. so cd into the TorqueWIN32 folder and run this make -f mk/configure.mk OS=WIN32 COMPILER=GCC3 BUILD=DEBUG course you can change BUILD to RELEASE when the time's right. Copy the xmake.sh script into the folder, and run it sh ./xmake.sh and it should spit out torqueDemo.exe in engine/out.GCC3.DEBUG/ ... so copy that into example cp ./engine/out.GCC3.DEBUG/torqueDemo.exe ./example/ change into the example directory and run it wine torqueDemo.exe and with any luck, starter.fps (or whatever main.cs is currently pointing to) will startup and you're away :)
Again, if you didn't get this far, post any and all error messages you got.. I have fiddled with my system a bit to get it to work exactly how I want, which is probably not the same as how you have yours but I'll be more than happy to help you with any errors if I can.
That should be you.. you know how to get Windows programs compiled on Linux now... and if you're really fancy.. setup a script for compiling Torque that changes the make configs to Linux, MAKEs it, changes the config to Win32, XMAKEs it, and you end up with Linux and Windows binaries of your codebase with one easy command :)
Again, incase you missed them above, here's the two files you'll need:
www.stuckieworld.net/public/xbuild.sh
www.stuckieworld.net/public/xmake.sh
Oh and don't ask about how to get Mac binaries done on Linux.. I'm still stuck at that myself, hehe.. but hope this is of use to some of you anyway.
Take Care,
Steven -=STUCKIE=- Campbell