[Gdal-dev] Universal GDAL build on OS-X ??

William Kyngesburye woklist at kyngchaos.com
Thu Oct 25 23:36:12 EDT 2007


Oh, there's a fun one.  And Python forces you to supply universal  
libraries to build extensions.  Though you might check the mac python  
mailing list - it may be possible to build a single architecture  
extension for the universal python.

First, as you speculate, there's the method that takes no patching of  
sources (a couple dependencies have minor endian issues) - build on  
both architectures and lipo them together.  But that's too much trouble.

The better way is to do it all at once on a single OSX architecture.   
It depends on where you want to start.  If you use universal  
dependencies and just build GDAL yourself from source, it's not too  
hard.  If you want to build all the dependencies yourself, that's  
quite a task.

You probably know about the arch flags needed, -arch ppc -arch i386,  
and the SDK, -isysroot /Developer/SDKs/MacOSX10.4u.sdk.  The isysroot  
flag is only really needed when building on PPC, since the system is  
not universal on PPC, though that will change with Leopard.  The  
isysroot flag has its own trap - /Library/Frameworks and /usr/local  
is not in it, so 3rd-party libs and frameworks will be missed unless  
some symlinks are added to it (I have details on that in my GRASS OSX  
readme, but haven't got them online yet).

There is an easy way to get the flags into the compile and link  
commands where needed:

http://www.macosxhints.com/article.php?story=20061025213851279

Otherwise getting them into CFLAGS, CXXFLAGS and LDFLAGS can be  
tricky (-isysroot can't be specified more than once).

The key for the sources is that some packages use a configured endian  
setting, instead of runtime endian detection (GDAL, netcdf, ogdi,  
tiff, xerces).  Some are even hardwired to assume that OSX is  
bigendian (hdf4, ecw).  Some have compiled data file endianess  
(proj), or run a program during compilation to set some platform  
endian info (hdf5).  One simply MUST be compiled separate and lipo'd  
- postgres - because it actually uses ld for linking instead of gcc,  
and ld is difficult to use with multiple arch flags.

The configured ones are easy - after running configure, edit the  
config.h file generated and conditionalize the endian setting on  
__BIG_ENDIAN__ or __LITTLE_ENDIAN__ - these are standard OSX GCC  
definitions.


SO, for GDAL, if you have all other dependencies universal, after  
running configure edit port/cpl_config.h and delete the two lines  
with WORDS_BIGENDIAN and HOST_FILLORDER, and replace them with:

#ifdef __BIG_ENDIAN__
   #define WORDS_BIGENDIAN 1
   #define HOST_FILLORDER FILLORDER_MSB2LSB
#else
   #undef WORDS_BIGENDIAN
   #define HOST_FILLORDER FILLORDER_LSB2MSB
#endif

You can't do this before running configure because configure  
magically zaps all define/undef lines.  I haven't tested this with  
the internal tif, gif, jpeg, png libs, since I use my UnixImageIO  
framework for those.


Universal-friendlyness is not something I can do much about, unless  
there is a lot of interest or I really get aggressive about it (I got  
GRASS to change).  One I'm thinking about pursuing (when other things  
settle down a bit) is PROJ.  The datum files are processed during  
compilation so they are endian-specific to the build platform (GRASS  
was like this for a couple things).  I have a patch I apply for my  
binaries that does byte-swapping depending on the architecture.

On Oct 25, 2007, at 7:11 PM, Christopher Barker wrote:

> How to I build GDAL to be Universal (PPC + Intel) on OS-X?
>
> I seem to have gotten GDAL itself to build, but now when the python  
> extension tries to build, I get errors because I'm using a  
> Universal Python, but it's trying to link with the libgdal.dylib,  
> which is PPC only (I'm on a PPC machine).
>
> William, you distribute universal binaries, so it must be possible.  
> Please tell me you don't build them separate and lipo them together!
>
> thanks,
> -Chris

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"Time is an illusion - lunchtime doubly so."

- Ford Prefect





More information about the Gdal-dev mailing list