Cross-Compiling : Do It Yourself

BlitzMax Forums/Brucey's Modules/Cross-Compiling : Do It Yourself

Brucey(Posted 2009) [#1]
This is considered an Advanced feature. It is assumed you are happy modifying your BlitzMax installation, and comfortable putting things back when things inevitably break ;-)

Now you too can compile Windows applications on Mac and Linux using a single build instruction. Yay!

This page explains how it all works, and what you need to get started :

http://brucey.net/programming/blitz/mingw/

Remember... back up things before you do anything. You have been warned!!

I'll release the source to the new bmk shortly. Still needs some tidying up. Everything else (including new MaxIDE source) is available from the page above.

Suggestions, comments and critique always welcome.

:o)


Mark Tiffany(Posted 2009) [#2]
For the benefit of others, I have done this and successfully built the Community Edition of MaxIDE on Linux and run the resulting exe on Windows. I am actually using it as my IDE now (just to ensure it's just the same) and have had no issues at all.

Once again, great job Brucey!


DavidDC(Posted 2009) [#3]
I just tested this on Intel Mac (Leopard). The instructions were simple to follow and there were zero problems setting it up. I thought it was going to be difficult but it was dead easy.

I tested some of the graphical code archives entries compiled on mac, target platform Windows, and they ran in XP perfectly.

That's the extent of my testing but all seems very well indeed.

Great effort Brucey :-)


TaskMaster(Posted 2009) [#4]
How do the exes differ from a mac compile and a windows compile? Are they bigger/smaller/almost the same size?


DavidDC(Posted 2009) [#5]
How do the exes differ from a mac compile and a windows compile? Are they bigger/smaller/almost the same size?

Well I just tested Imaginary Human's blobby plasma in release mode.

On Mac (compiled for windows) -> 1,067KB
On XP compiled natively -> 1,067KB

Hardly a definitive test I admit.


Brucey(Posted 2009) [#6]
Are they bigger/smaller/almost the same size?

With this little test :
SuperStrict

Framework BRL.StandardIO

Print "Hello"


Here are some results :

Windows (native) -
  Release :  52,224 bytes
  Debug   : 100,352 bytes

Linux (cross) -
  Release :  50,176 bytes
  Debug   :  98,816 bytes

Mac (cross) -
  Release :  51,712 bytes
  Debug   :  99,840 bytes


Not very scientific.


Mark Tiffany(Posted 2009) [#7]
Brucey - obviously you've done an awful lot already, and I don't want to sound ungrateful...but how hard would it be to get Linux compiling on Intel Mac? I'm just thinking of the *nix connection, and presumably the required Linux components (esp gcc) are all freely distributable under presumably open source type licenses...

It's just that then MacOS could compile all platforms in one swoop, which would be a rather nifty achievement, and would be rather useful for people to use an Intel Mac as a one-stop compiling stop...


Brucey(Posted 2009) [#8]
If you can persuade Mr Sibly to create a Mac binary of the Linux bcc, then it should be no problem (in theory). I get by the Windows issue by using Wine to run the Win32 bcc and fasm.

:-)


Mark Tiffany(Posted 2009) [#9]
Ah, yes, of course. Well, here's hoping, and my in progress CE IDE tweaks to support all this won't take much to enable for other platforms if/when they arrive...


plash(Posted 2009) [#10]
It'd be awesome if bcc and fasm could be modified to do all compilations for all platforms, and simply accepts a parameter telling it which to compile to.

I'll be trying this later.


Mark Tiffany(Posted 2009) [#11]
As others have said, compiling to MacOS from outside is unlikely due to the dependency on XCode. But I think all the other directions might be possible...and really, we "just" need Linux from MacOS enabled, making an Intel Mac the only platform of choice for cross-compiling BlitzMaxers.


Brucey(Posted 2009) [#12]
making an Intel Mac the only platform of choice for cross-compiling BlitzMaxers.

Yay! :-p


On another interesting note, (if you like these kinds of things), this new BMK also handles post build scripts. It will look for a file called post.bmk in the build folder and execute it. The script is pseudo-lua, insofar as the code inside the "function" definitions is pure lua... but it is wrapped up slightly differently because it is parsed and "added" to BMK at runtime to introduce new functionality.

Here's one I've just knocked together to help me with the PRP (Pocket Radio Player) build on Mac :
# MacOS post build script
#
#
@define doPostInstall

	# only interested for Mac platform
	
	if bmk.Platform() == "macos" then

		local path = utils.ModulePath("bah.fmod") .. "/lib/" .. bmk.Platform() .. "/"
		local file = "libfmodex.dylib"

		# copy FMOD
		sys.CopyFile(path .. file, %exepath% .. "/" .. file)
		
		#copy icons
		sys.CopyFile(%buildpath% .. "/data/prp.icns", %exepath% .. "/../Resources/" .. %outfile% .. ".icns")

	end

@end

# run the post install
doPostInstall

It copies the fmod dylib and the custom icons into the application bundle - so I don't have to faff around with that everytime I get a new set of source to build.
And of course, with the Universal Build option, it does a combined PPC + x86 build of PRP with a single click ;-)

THIS is what developing in BlitzMax should be all about : Single-click multi-platform builds. No hassle. No stress.

:-p


DavidDC(Posted 2009) [#13]
If you can persuade Mr Sibly to create a Mac binary of the Linux bcc...
Ah, yes, of course. Well, here's hoping

Surely we can do more than hope? If we petition Mark, either individually or en-masse, at the very least we can expect a response?

How hard would a Mac binary of the Linux bcc be for Mark to create do you think Brucey?


therevills(Posted 2009) [#14]
Excellent work Brucey!

With the new BMK (NG), what do I need to do just to get Universal Binaries to work on an Intel Mac? I dont need to Win32 stuff - I develop on WinXP, then port to Mac...

BTW What does the NG stand for? (Next Generation?)


Tachyon(Posted 2009) [#15]
What I'd love to see is an Intel Mac be able to make a PPC Mac compiled executable. At one time Mark hinted this might be possible.


DavidDC(Posted 2009) [#16]
Tachyon: What I'd love to see is an Intel Mac be able to make a PPC Mac compiled executable. At one time Mark hinted this might be possible.
Brucey: And of course, with the Universal Build option, it does a combined PPC + x86 build of PRP with a single click ;-)

Brucey's already done that :-)


Tachyon(Posted 2009) [#17]
=D

Zowie! How did I miss that?!?!

Brucey is amazing.


Brucey(Posted 2009) [#18]
what do I need to do just to get Universal Binaries to work on an Intel Mac?


1) You'll need the PPC bcc app copied into your BlitzMax/bin, and renamed to bcc_ppc

2) I've added a -i option to BMK, which will take care of everything else. You will need to build modules using this option before you can build apps. (for obvious reasons).

3) There's an updated IDE on the website which has the Universal build option.

What does the NG stand for? (Next Generation?)

Yeah.. sad isn't it? :-p


therevills(Posted 2009) [#19]
Thanks Brucey... Ill have a go soon :)

Whats sadder, you calling it NG or me guessing it? LOL


Mark Tiffany(Posted 2009) [#20]
SVN version of the CE IDE now includes support for cross-compiling! Link in my signature.

(Note: untested on Mac, but should all work!)


Otus(Posted 2009) [#21]
Nice, playing with it at the moment using Linux.

I was just wondering, why do you use the Windows fasm executable on Linux? Shouldn't the Linux one work the same?

Edit: Ok, got a libc error (GLIBC_2.8 not found). I have Hardy with GCC 4.2.4 and libc6 (2.7). I'll have to see if I can get newer ones installed.


Brucey(Posted 2009) [#22]
I'll have to see if I can get newer ones installed.

The other option of course, is to create a build of mingw for libc6 2.7.

Shouldn't the Linux one work the same?

Probably. It doesn't really make any difference, as far as I can tell. But for ease of porting, I chose to use the windows exe for both Mac and Linux (I couldn't find a Mac-build of fasm).


Ked(Posted 2009) [#23]
I just now skimmed through this thread and just to make sure I've got everything: You can only compile from Mac -> Win32 and Mac -> Linux? No Linux -> Mac or Linux -> Win32 or Win32 -> Mac or Win32 -> Linux? Once we are able to compile from Win32 -> Mac and Linux, this will be very useful for me! :) Anyways, good work on this.


Brucey(Posted 2009) [#24]
You can only compile from...

No... you can do Mac->Win32 and Linux->Win32.
(and Mac->Universal Mac)


Otus(Posted 2009) [#25]
The other option of course, is to create a build of mingw for libc6 2.7.


Took some time, but I finally got it working. I managed to build all modules and at least a HelloWorld program cross-compiles and runs on Vista.

I had some problems building MinGW, so I ended up using the build from Ubuntu "universe" repository. The layout was different, so I had to rewrite all the paths in config.bmk. Here's my config if someone else wants/needs to use the same method:



plash(Posted 2009) [#26]
Brucey's setup worked perfectly for me (Ubuntu 9.04).

Now.. Is it possible to make the Linux/Mac bmk_ng compile win32 code with the optimizations in the Windows bmk_ng?


Otus(Posted 2009) [#27]
Now.. Is it possible to make the Linux/Mac bmk_ng compile win32 code with the optimizations in the Windows bmk_ng?


In make.bmk you'll find default_cc_opts. Just change -Os to whatever.

However, I made a small regex test program. Some speed results:

Native/w Os: 4638ms
Cross /w Os: 6089ms
Cross /w O2: 6030ms

I think my mingw-gcc 4.2.1-sjlj is to blame.


John G(Posted 2009) [#28]
Creating an easy "Universal Binary" Mac app from a Mac would be wonderful.
Creating a WinTel PC app from a Mac would be Nirvana! Good luck.

Cheers


Brucey(Posted 2009) [#29]
Good luck.

It already works a treat ! Although it does require an Intel Mac. (as does the Universal option).


John G(Posted 2009) [#30]
Oh, I meant good luck with the second part : Mac Intel ==> Win App.
I knew the Mac Universal one was easy -- cough, cough.
No wait, you're saying the second part is done?

Have PPC Mac and wife has Intel Mac but no Win PC.


xlsior(Posted 2009) [#31]
No wait, you're saying the second part is done?


Yup, thanks to Brucey the Magician you can create Win32 exe's on a Mac now.


anawiki(Posted 2009) [#32]
Just tested it. I'm soooo happy that I don't need my G4 anymore. Donated $50. Have few beers on me ;-)

cheers
Roman


Brucey(Posted 2009) [#33]
Thanks very much! :-)

I'm glad you are finding it useful.
Anything to make ones like easier, I say!


Ked(Posted 2009) [#34]
What about Win32 -> Linux/Mac?


Brucey(Posted 2009) [#35]
What about Win32 -> Linux/Mac?


Nah. It's much more fun the other way around :-)


Ked(Posted 2009) [#36]
Nah. It's much more fun the other way around :-)

Sigh. Except for the Windows people.


Brucey(Posted 2009) [#37]
Well, at the moment it is technically impossible (on the BlitzMax side) to do this.
Hence, I haven't currently a solution for your request.

Of course, there's nothing to stop you installing Linux and developing on there ;-)


therevills(Posted 2010) [#38]
Finally got around and trying this today.

Worked brilliantly for the Universal Binary (using your custom MaxIDE :)), built the game on our Intel Mac Mini and tested on the old G4 Mac Mini :)

Thanks a lot Brucey :)


Brucey(Posted 2010) [#39]
You're welcome :-)


CASO(Posted 2010) [#40]
Compiling:blitz_ex.win32.x86.s
sh: /Applications: is a directory
Build Error: Failed to assemble /Users/calebsolano/BlitzMax/mod/brl.mod/blitz.mod/blitz_ex.win32.x86.s

I get this in the terminal as well as IDE

Also, the article says there are "lib" files....there were none. I'm on OS X FYI.


ima747(Posted 2010) [#41]
First off thanks for this, can't wait to get it going as it's going to save me TONS of time, however I've hit a snag

Installed and copied everything to my intel mac, compiles intel mac fine. Using BMK(NG)2.07, MaxCE 2.01 and bmax 1.38, bcc and fasm were taken from 1.38 running on my PC and bcc_ppc was taken from 1.38 running on my PPC mac

I can compile a test hello world app for windows fine however when I compile my current project for windows I get the following error. it compiles all the other source files for the app (which are in a sub directory) and then when it trys to link the exe I get this
/usr/local/i386-mingw32-3.4.5/bin/i386-mingw32-ld: cannot find -lunicows
followed by build error: failed to link

I'm assuming from what I can find that lunicows is a lib that is needed for maxgui on windows, but don't know where to find it or where to put it...

additionally the mingw disc image I downloaded (twice to be safe...) says "There may be a problem with this disk image. are you sure you want to open it? opening this disk image may make your computer less secure or cause other problems." just thought you should know if the warning. osX 10.6.2 if it matters

Also what is the command line to compile the mods for PPC?


CASO(Posted 2010) [#42]
I fiddled with it an discovered I actually needed
# The path to Wine executable
#
path_to_wine=/Applications/Darwine/Wine.bundle/Contents/bin/wine



ima747(Posted 2010) [#43]
CASO got to my other note before I could remember :0)

the path_to_wine default is /usr/bin/wine which is probably the default for Linux I'm thinking...


ima747(Posted 2010) [#44]
I managed to fix the /usr/local/i386-mingw32-3.4.5/bin/i386-mingw32-ld: cannot find -lunicows error finally.

download the mingw32 version of libunicows from [a]http://libunicows.sourceforge.net/[/a]
copy the 2 .a files to your /usr/local/i386-mingw32-3.4.5/i386-mingw32/lib folder (you will need your admin password for permission as the folder is restricted)

windows compiles with MaxGUI now work for me. They don't run through wine, but when I send them over to my PC they work fine. Not a real extensive test of reliability so perhaps when Brucey gets a chance he can comment and say if I did something wrong, or can expect problems (for the record I don't care about windows bellow XP for my application)

Also of note, using maxide-ce when I compile modules it gives me a warning at the end saying compile failed but everything seems to work fine despite that, perhaps it's not recognizing the module compile return and assumes it's an error?


Robert Cummings(Posted 2010) [#45]
Brucey you wouldn't be available for paid work would you? It's just you're a bit of a neat problem solver and I think throwing cash at you might take some of the pain away one day. Not that I have any pain at the moment!


siread(Posted 2010) [#46]
I managed to compile a universal binary which works fine on my Intel Mac but I don't have a PPC to test it on. Could someone check this out for me?

http://download.newstargames.com/private/SWS_FullUni.zip

Thanks. :)


siread(Posted 2010) [#47]
The above app doesn't work on PPC. It crashes almost immediately (after setting up a few files ok in the documents folder) and produces this crash log:

http://download.newstargames.com/temp/Error.rtf

Any ideas would be much appreciated. :)


Brucey(Posted 2010) [#48]
Running it on actual PPC hardware ( :-p ), I get this error :
Thread 0 Crashed:
0   Sensational World Soccer  	0x0006db98 11 + 40
1   Sensational World Soccer  	0x0000ca00 bb_SetUpFonts + 88
2   Sensational World Soccer  	0x0000ec84 bb_SetUpFryGui + 124
3   Sensational World Soccer  	0x0000e548 5558 + 16
4   Sensational World Soccer  	0x00007aec 4891 + 108
5   Sensational World Soccer  	0x00003af4 4 + 48
6   Sensational World Soccer  	0x00003b54 run + 68


Note that the backtrace you see when a PPC app fails on Intel is generally not very helpful.
Hope this helps to track down the issue.

You can mail me privately if you want some more testing done... - debugging or otherwise :-)


siread(Posted 2010) [#49]
Thanks Brucey. :)


Spot-Nothing(Posted 2011) [#50]
Hi Brucey,

Does anyone know if it's theoretically possible to use the MinGW using MacPorts with ? See here: http://www.macports.org/ports.php?by=name&substr=mingw

And: The lib folder seems to be empty on your download page. Is it available somewhere else?


Brucey(Posted 2011) [#51]
It should be possible to use this... probably just a case of setting up the correct paths in the .bmk file.


Chroma(Posted 2011) [#52]
Donated $50. Have few beers on me ;-)
Meh...where's the donate button?? The Chipmunk module is pretty much making my next game even possible. Very much appreciate your hard work Brucey.

Last edited 2011


Russell(Posted 2011) [#53]
All those in favor of Brucey putting a "Donate" link in his signature, raise your hands...

Russell


Hardcoal(Posted 2015) [#54]
(Y)ohhh.. didnt notice its an old post .. :(