[postgis-users] OSX Server (Lion) link failures with Apple-provided PostgreSQL

William Kyngesburye woklist at kyngchaos.com
Wed Sep 14 14:23:28 PDT 2011


From all this, it looks to me like Apple's Postgres is standard behavior.

Basically, as you say, you must compile Postgres extensions with the same architectures as Postgres.  And to do this you use the PG_CPPFLAGS and SHLIB_LINK variables.  These two are needed because they don't inherit from CFLAGS or LDFLAGS, and is normal behavior (though maybe an oversight for Postgres?).  (my instructions setting CFLAGS and LDFLAGS as well is probably just my making sure, since makefile.global, at least, forces LDFLAGS to include the Postgres-configured archs.)

If you want to compile only one architecture, then yes you need to do some hacking.  But there's nothing wrong with Postgres or Postgis makefiles.  

You could copy the whole pgxs folder and pg_config and change them all to be self-consistent, plus your hacks.  I do something similar so I can build multiple copies of Postgres and Postgis for different OSX versions and shared/static library configurations.  Your custom pg_config needs to point to your custom pgxs.  your custom makefile.global has your hacks.  configure postgis with --with-pgconfig=/path/to/your/pg_config.


On Sep 14, 2011, at 3:47 PM, Jerry Carter wrote:

> Figured it out.  I believe that the PostGIS makefiles need to be changed for Lion Server.  There is a workaround but I am unable to provide a more appropriate patch.
> 
> System description:
>  * OS X Server 10.7.1 (Lion) running in 64-bit mode
>  * XCode 4.2 (4D177b) which includes GCC version 'i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1'
>  * PostgreSQL 9.0.4 as built by Apple
> 
> Problem:
> 
> Following the normal steps
> 
> 	cd postgis-1.5.3
> 	./configure
> 	make
> 
> compilation succedes but the link fails.
> 
> 	ld: warning: ignoring file ../liblwgeom/liblwgeom.a, file was built for archive which is not the architecture being linked (i386)
> 
> Looking back at the output, you will notice that the arguments used for compilation of postgis specify two architectures: "gcc -arch x86_64 -arch i386 …"
> 
> 
> The problem is that the provided version of Postgres expects PostGIS to be a hybrid 32/64 bit library.  To understand why this is occurring, we must follow the convoluted chain of makefiles.  Starting at the top, the 'make' command invokes the 'Makefile' which on this platform triggers several commands including a 'gnumake -f GNUmakefile postgis'.  This in turn invokes the 'postgis/Makefile' which includes the build infrastructure for Postgres extensions (/usr/lib/postgresql/pgxs/src/makefiles/pgxs.mk) that brings in '/usr/lib/postgresql/pgxs/src/Makefile.global'.  Doing this ensures that PostGIS is built using the same compiler settings as PostgreSQL.  Apple builds Postgres as a universal binary, a hybrid of 32 and 64 bit, and they expect all extensions to do likewise.
> 
> Workaround:
> 
> sudo cp /usr/lib/postgresql/pgxs/src/Makefile.global /usr/lib/postgresql/pgxs/src/Makefile.global.orig
> sudo vi /usr/lib/postgresql/pgxs/src/Makefile.global
> # remove either '-arch i386' or '-arch x86_64' from the CFLAGS and LDFLAGS definitions as appropriate, e.g. remove i386 for 64 bit platforms.
> 
> 
> Better Solution:
> 
> Rejigger the PostGIS makefile to build a hybrid library.
> 
> For the dependencies, this is straightforward.  Here are the steps for Proj.4:
> 
> 	cd proj-4.7.0
> 	./configure
> 	make
> 	sudo make install
> 
> 	setenv LDFLAGS="-arch i386 -m32"
> 	setenv CFLAGS="-arch i386 -m32"
> 	setenv CXXFLAGS="-arch i386 -m32"
> 	./configure --host=i386-apple-darwin11.1.0
> 	make clean
> 	make
> 	lipo create src/.libs/libproj.0.6.6.dylib /usr/local/lib/libproj.0.6.6.dylib -output libproj.0.6.6.dylib
> 	sudo mv libproj.0.6.6.dylib /usr/local/lib/libproj.0.6.6.dylib
> 	sudo chown root /usr/local/lib/libproj.0.6.6.dylib
> 	unsetenv LDFLAGS
> 	unsetenv CFLAGS
> 	unsetenv CXXFLAGS
> 
> The steps for GEOS are similar.
> 
> Similar steps work for PostGIS.  These can be done manually but I'm not sure how to automate them with the current make environment.
> 
> 
> 
> On Sep 14, 2011, at 11:16 AM, Jerry Carter wrote:
> 
>> 
>> I'm trying to compile PostGIS 1.5.3 and getting tripped up with 32 vs. 64 bit.  Following the normal process,
>> 
>> 	cd postgis-1.5.3
>> 	./configure
>> 	make
>> 
>> compilation proceeds but the link fails.
>> 
>> 	ld: warning: ignoring file ../liblwgeom/liblwgeom.a, file was built for archive which is not the architecture being linked (i386)
>> 
>> On the linking step, I noticed that the architecture flags specify both 32 and 64 bit, i.e. "-arch x86_64 -arch i386", but can't figure out how to disable 32 bit.  I've already rebuilt Proj.4 4.7.0 and GEOS 3.2.2 as hybrid 32+64 bit libraries.
>> 
>> Any suggestions to either disable 32-bit entirely for PostGIS or to get the makefiles to build liblwgeom as a hybrid?  Thanks much.
>> 
>> -=- Jerry
>> 
>> P.S. I am using GCC version 'i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1' which is shipped with Xcode 4.2.
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

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

"This is a question about the past, is it? ... How can I tell that the past isn't a fiction designed to account for the discrepancy between my immediate physical sensations and my state of mind?"

- The Ruler of the Universe





More information about the postgis-users mailing list