When compiling source outside the ports tree on FreeBSD the default 'configure' file produces link options that conflict with the libraries python is built with in ports. This leads to the following error message with apache tries to load the python module:
- Cannot load /usr/local/apache2/modules/mod_python.so into server:
- /usr/local/apache2/modules/mod_python.so: Undefined symbol "pthread_attr_init"
This is the result of linking mod_python against the threaded /usr/lib/libc_r.so, but apache and python being linked against the non-threaded version. This error can be circumvented by setting the environment variable LD_PRELOAD=/usr/lib/libc_r.so, but that sets the dynamic link environment for all threads and subprocess of the apache http. However, problems arise when trying to shell out to scripts that are written for interpreters that were linked against the non-threaded libc, such as expect, bash or ksh. Simple examples will succeed, but trying to use "spawn" in expect or execute co-processes in ksh cause the scripts to hang and consume large amounts of CPU cycles.
The solution is to compile using the same libraries that python was linked against from the ports tree, and the port maintainers are kind enough to provide a patch for the configure script in ports.
Here is the content of the patch for version 3.1.4. It applies with minor warnings to the source for versions 3.2.10 and 3.3-svn at the time of this writing. I will attach it as a downloadable file if the WiKi allows that:
--- configure.orig Sun Jan 30 06:25:27 2005
+++ configure Wed May 18 12:06:06 2005
@@ -2643,7 +2643,7 @@
PyLIBP=${PyEXEC_INSTALLDIR}/lib/python${PyVERSION}
PyLIBPL=${PyLIBP}/config
PyPYTHONLIBS=${PyLIBPL}/libpython${PyVERSION}.a
-PyLIBS=`grep "^LIB[SMC]=" ${PyLIBPL}/Makefile | cut -f2 -d= | tr '\011\012\015' ' '`
+PyLIBS=`ldd $PYTHON_BIN | sed -n 's,^.* => [^ ]*/lib\(.*\)\.so[^ ]* \((.*)\),-l\1,p' | grep -v '^-lc$' | xargs echo`
PyMODLIBS=`grep "^LOCALMODLIBS=" ${PyLIBPL}/Makefile | cut -f2 -d= | tr '\011\012\015' ' '`
PyFRAMEWORK=`grep "^PYTHONFRAMEWORK=" ${PyLIBPL}/Makefile | cut -f2 -d= | tr '\011\012\015' ' '`
PyFRAMEWORKDIR=`grep "^PYTHONFRAMEWORKDIR=" ${PyLIBPL}/Makefile | cut -f2 -d= | tr '\011\012\015' ' ' | awk '{print $1}'`Note that it uses the python executable as the source for libraries rather than the Makefile which probably won't be on your system unless you compiled python yourself.