Benches Uncategorized

3

Compiling a universal binary with gcc

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I'm trying to build a unix application for my mac. I can compile i just fine using the configure and makefiles. However, this only makes an intel executable. I need a universal executable.

I was told that setting LDFLAGS="-arch 'i386' -arch ppc" would do that for me.

However, when I do that, the configuration script fails and says:

gcc-4.0: Invalid arch name : 'i386'

now man gcc tells me that the valid arguments after -arch are i386, ppc, x86_64 and ppc64. so, why would gcc be complaining about this?

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    etresoft

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    It is probably the single quotes.

    In any event, you need more than that. Try “-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch ppc -mmacosx-version-min=10.5" for a 10.5 build. Also, it should be in CFLAGS. Construct your configure like like so:


    CFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch ppc -mmacosx-version-min=10.5" ./configure

    It may be safer to build each architecture separately and then use lipo to assemble the final executable. It all depends on how well the project in question handles endian-ness and bit depth. Most things should be fine, but I'm sure there are outliers.

  2. 0

    Brian Postow

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Well, it's partially right. The single quotes were the problem. For some reason adding the -isysroot in there completely messes up the include paths, but when I take that out the libraries at least will compile, and appear to be universal.

    However, when I compile the main program it doesn't link... Without going into details, Since you're giving me basically agrees with what I'd already seen I'm thinking that the problem is that the arguments aren't getting used correctly in the final makefile... If I just use -arch ppc that SHOULD just make a powerPC version, right?

    hrm...

  3. 0

    etresoft

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Brian Postow wrote:

    For some reason adding the -isysroot in there completely messes up the include paths,

    It shouldn't.

    However, when I compile the main program it doesn't link... Without going into details,

    Those can be handy.

    Since you're giving me basically agrees with what I'd already seen I'm thinking that the problem is that the arguments aren't getting used correctly in the final makefile... If I just use -arch ppc that SHOULD just make a powerPC version, right?

    You may need to add these values to LDFLAGS too, or to CC, CXX instead. I detest autoconf.