iprog.com

Compiling mod_xsendfile for OS X

Today I needed to compile mod_xsendfile for OS X on Intel. The standard command for this,

apxs -cia mod_xsendfile.c

resulted in a module that was for i386 only.

Apache on Leopard (untested on Tiger) doesn’t appreciate this, throwing this error:

4/7/08 5:08:08 PM org.apache.httpd[ 15990] httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_xsendfile.so into server: dlopen(/usr/libexec/apache2/mod_xsendfile.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/mod_xsendfile.so: mach-o, but wrong architecture

Turns out the solution is pretty simple. Just change the command to apxs to this:

apxs -cia -Wc,"-arch x86_64 -arch ppc -arch i386 -arch ppc64" -Wl,"-arch x86_64 -arch ppc -arch i386 -arch ppc64" mod_xsendfile.c

This will generate a fat-binary for all four current Mac architectures.

11 comments