I am a linux fan… But I know that I am part of a minority of users. So when I develop a software, I try to make it work on windows and macosx.
This seems natural, but all developer know that it’s a hard task. For the past 10 years, I principaly develop in java. So the cross platform problem wasn’t impacting my development. BUT when developping in java, there is an important pre requisite: all users has to have THE version of java I developing for.
For some reasons, I started studying others way to develop cross platform application using a native language (c++) with a cross platform framework (qt). Using qt and cmake, I am able to write the same code and compile it to the differents oses.
At this point I am quite productive. The same code can be compiled on windows, linux and mac without any changes. Using a continuous integration server, and configuring a linux, mac and windows clients, I can then generate the software for all platforms.
But I always dream on an universal compiler able to generate the 3 binaries from my linux. It was quite easy to create a cross compiler for windows, using mingw (as it come with ubuntu), but for mac, there was nothing similar !
Clang
Some month ago, I found this page: http://clang.llvm.org/UniversalDriver.html
Great! Someone is working on the compiler I was dreaming on ;)
So let’s try it:
First with a simple program:
include <stdio.h>
int main() {
printf("hello world\n");
}
Linux
And compile it (for linux):
clang -o hello hello.c
Work like a charm !
windows
$ clang -ccc-host-triple i386-pc-mingw32 -o hello hello.c /tmp/hello-Rz8VW3.s: Assembler messages: /tmp/hello-Rz8VW3.s:1: Error: unknown pseudo-op: `.def' /tmp/hello-Rz8VW3.s:2: Error: unknown pseudo-op: `.scl' /tmp/hello-Rz8VW3.s:3: Error: Missing symbol name in directive /tmp/hello-Rz8VW3.s:3: Error: unrecognized symbol type "32" /tmp/hello-Rz8VW3.s:4: Error: unknown pseudo-op: `.endef' clang: error: assembler (via gcc) command failed with exit code 1 (use -v to see invocation)
Not so easy… looking with details, it show me that it was executing gcc for linking :(
Looking on the clang code, I can see that mingw is not supported. So I should try with a native windows triple like i386-pc-win32. But as it use the visual studio tools, it obviously won’t work for linking…
So what about just compilation ?
$ clang -ccc-host-triple i386-pc-win32 -o hello.o -c hello.c $ file hello.o hello.o: 80386 COFF executable not stripped - version 30821
Well… I have an half cross compiler at this time. I will try to fix this next week…
Mac
For the moment, go for the mac compilation !
As exptected the linking phase fails, as I still doesn’t compile the binutils equivalent for macosx.
But for the compilation, it work fine:
$ file hello.o hello.o: Mach-O object i386
It look like interesting. I am able to generate a mac object file from linux!
Before starting with the big stuff of binutils compilation, play with the clang compiler:
iOS
$ clang -v -ccc-host-triple arm-apple-darwin -o hello.o -c hello.c $ file hello.o hello.o: Mach-O object acorn
That’s a great news: I also can generate mach-o arm object files. That’s the first step to cross compile for iOS !
I will post this week another post on the macosx binutils compilation…


Develop a mobile web app in HTML, JS, CSS, Ajax and jeMbe API. Then compile it into .ipa (iPad, iPhone) or .apk (Android) with jeMbe software


