As I had quite some problems compiling & running the PHP bindings on Mac OS X (missing symbols during linking, crashing Apache) & there have been questions before, I'd like to share my solution, which seems to work fine as of now.

Short version:
Change the PHP_LDFLAGS variable in php/Makefile (line 135) to
-lrdf -bundle_loader /path/to/php -flat_namespace -bundle

I am no expert on this, so if there is a better way to compile on Mac OS X, I would appreciate very much the information.

My environment:
Mac OS X 10.5.4, Apple-installed Apache 2, self-compiled PHP 5.2.5. Because PHP is compiled in 32 Bit (some extensions, for the configure command see below), I had to strip down the httpd-binary to i368- architecture with lipo[1] (I don't think this influences the linking problems, but I'm not sure). Redland librdf 1.0.8, php bindings version 1.0.8.1.

Options (all concerning the linker ld[2] called from the compiler, I think)

My configure command:
./configure --with-php=/path/to/php --with-php-linking=so --with- redland=system LIBS='-lrdf'

-bundle instead of -shared
man gcc[3] on Mac OS X says about "-shared": "This option is not supported on MacOSX". The appropriate switch for ld is -bundle (you can still name the library .so, I think it doesn't matter, because it isn't loaded dynamically)

-lrdf
search symbols in librdf.dylib to eliminate missing symbols from redland (I have redland installed at the default /usr/local location, so ld finds it. The LIBS='-lrdf' configure option doesn't incluence here the php bindings Makefile, btw).

-bundle_loader /path/to/php
this is the way ld on Mac OS X resolves the symbols from PHP - as there is no way linking directly to the libphp5.so (ld usually only resolves symbols in dynamic libraries (.dylib))

-flat_namespace
I know next to nothing about this option (found it by trial and error), except that it stopped Apache processes from crashing with messages like "Dyld Error Message: Symbol not found: _executor_globals". It seems to have something to do with thread safety (whatever that is). ld[2] has to say that:

"Two-level namespace
By default all references resolved to a dynamic library record the library to which they were resolved. At runtime, dyld uses that information to directly resolve symobls. The alternative is to use the -flat_namespace option. With flat namespace, the library is not recorded. At runtime, dyld will search each dynamic library in load order when resolving symbols. This is slower, but more like how other operating systems resolve symbols."

On the Apple dev lists, there is quite some discussion about 2-level and flat namespaces, it seems to be a constant problem when porting software from Linux to Darwin. As I only develop on Mac OS X and deploy on Linux servers, I don't very much care right now about possibly slower performance.

I hope this helps somebody, otherwise please excuse the noise,

Cheers,

Martin
[EMAIL PROTECTED]
Berlin, Germany

[1] <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/lipo.1.html > [2] <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/ld.1.html > [3] <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/gcc.1.html >

PHP configure command:

./configure' '--prefix=/usr/local/php5' '--with-config-file-path=/ Users/martin/dev/php/ini' '--with-apxs2=/usr/sbin/apxs' '--with-zlib' '--with-zlib-dir=/usr' '--enable-calendar' '--with-pear' '--with- sqlite' '--with-mysql=/sw' '--with-pdo-mysql=/sw' '--with-mysqli=/sw/ bin/mysql_config' '--with-iconv=/sw' '--enable-mbstring' '--with- readline=/sw' '--with-mcrypt=/sw'

_______________________________________________
redland-dev mailing list
[email protected]
http://lists.librdf.org/mailman/listinfo/redland-dev

Reply via email to