Archive

Archive for April, 2008

Using GDC to compile a Universal Binary on PPC Mac OS X

April 25th, 2008 No comments

I’m blogging this more as a reminder for myself, but seeing as I can’t find this information anywhere else, I may as well log it for everyone to see. The same rules should apply for GCC and G++ as well, you just don’t need to worry about the Phobos library part.

I’m working on a cross platform project using DigitalMars D, which means that I’m not using XCode to build it (instead I’m using an Ant build script) – however, I still have XCode 2.2 installed so that I can build Universal Binaries. To make things more complicated, I am compiling my code without linking, and then linking all the object files later.

So at compile time:

gdc <filename> -o <output-filename> <loads of other options that aren’t important here> -arch ppc -arch i386

This will compile your .d file into your output file, with two architectures. You can test this using the “file” command in the command line:

file <output-filename>

This should report the different architectures you have built for.

At link time, things become more complicated. Instead of using the ordinary system root, you need to specify the correct SDK where Universal Binary libraries have been installed by XCode:

g++ <list of object files> -o <executable-name> -arch ppc -arch i386 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk

This should link everything together nicely…. except you receive an error about not finding “gphobos”.

If you have installed GDC properly (and a Universal Binary build at that), you should be able to find the file “/usr/lib/libgphobos.a”. This is already compiled as a Universal Binary library, so don’t panic about having to recompile (as I did), the problem is that “ld” cannot find the library in the SDK directory. So all you need to do is create a symlink in “/Developer/SDKs/MacOSX10.4u.sdk/usr/lib”:

cd /Developer/SDKs/MacOSX10.4u.sdk/usr/lib ln -s /usr/lib/libgphobos.a libgphobos.a

If you try the G++ command again, it should link quite nicely.

Reading other related posts on the internet, it seems you can specify -arch ppc64 and -arch x86_64 to the compile and link statements. I also believe that the Phobos library is built for this already as well, however I’m saying that from memory so I may be wrong. I haven’t tried those architectures (yet!), so your mileage may vary.

Categories: Uncategorised Tags: