Getting Apache to Link the stdc++ Library

There are a number of global symbols used by C++ programs which are found in the C++ Standard Library library which is not normally needed by the Apache library. Normally the C++ compiler/linker takes care of linking the appropriate libraries to C++ programs but in the case of a C driver (e.g. apache) dynamically loading a C++ shared object the linker is not involved.

You can dynamically load arbitrary shared objects (and their global symbols) into apache using the LoadFile directive in the httpd.conf file. This directive must be specified before any LoadModule directive which loads a C++ module.

The file you need to load will be a different file depending on your distribution (for Linux), your compiler version, your c++ standard library version, and your OS. You can compile a dummy C++ program and then use the ldd command to determine which file holds the correct version and location of the standard C++ library.

Do not forget to update your httpd.conf file everytime you upgrade your standard C++ library

Examples

find_gnu_stdlib.sh

#!/bin/sh

# This script is for use with GNU g++
echo "void main() {}" > /tmp/foo.cpp
g++ -o /tmp/foo /tmp/foo.cpp
ldd /tmp/foo | grep libstdc++
rm -f /tmp/foo /tmp/foo.cpp

find_solaris_stdlib.sh

#!/bin/sh
# This script is for use with Solaris WorkShop Compilers CC
# Thanks to Michael Tilburg <mtilburg@macromedia.com>
echo "int main() {}" > /tmp/foo.cpp
CC -o /tmp/foo /tmp/foo.cpp
ldd /tmp/foo | grep libC
rm -f /tmp/foo /tmp/foo.cpp

httpd.conf

LoadFile /usr/lib/libstdc++-libc6.1-1.so.2
LoadModule cpphello_module /usr/lib/apache/1.3/mod_cpphello.so   

Zachary C. Miller
Last modified: Sat Aug 12 04:07:22 CDT 2000