views:

342

answers:

3

I am referring to the following source: http://clpbar.sourceforge.net

Build process is the standard: ./configure followed by make

If I build on 10.5 I get a binary whose file contains: Mach-O executable i386
If I build on 10.6 I get a binary whose file contains: Mach-O 64-bit executable x86_64

How can I build from the command line on 10.6 and produce an executable of the type Mach-O executable i386, or even better a Universal binary containing executables of both types.

Please test any suggested solutions.

Thanks,
matt

A: 

Use a -arch flag for each target. So, e.g.

gcc -arch i386 -arch x86_64 ...

would build a fat binary with both. I believe by default gcc builds to the target architecture, which is x86_64 with OSX 10.6.

jeffamaphone
+1  A: 

By default, the version of GCC distributed with OS X 10.6 builds 64-bit binaries. The version of GCC distributed with 10.5 builds 32-bit binaries by default.

Before running ./configure, set a few environment variables. If you want it to be an Intel universal binary with i386 and x86_64 code, set the following variables (assuming you're using bash):

export CFLAGS="-arch i386 -arch x86_64"
export CXXFLAGS=$CFLAGS
export LDFLAGS=$CFLAGS

This will tell the configure script to pass these compiler and linker options, and thus build a binary with both the i386 and x86_64 architectures.

Or, if you want it to only build as an i386 binary:

export CFLAGS="-arch i386"
export CXXFLAGS=$CFLAGS
export LDFLAGS=$CFLAGS
Grant Limberg
I just tried this and it didn't work. Could it be that the environment variables are being overridden by ./configure?
matt
+3  A: 

From the Apple dev forums:

./configure CC="gcc -arch i386" CXX="g++ -arch i386"

Which works perfectly.

matt