C.1. Statistically Linked Modules That Need External Libraries

If you have a module that requires one or more external library files and you wish to link it into the httpd binary statically, then you have to arrange for the library to be added to the LIBS variable that the httpd makefile uses for the link phase. The most straightforward way to achieve this is to provide a "hint" to Apache's configuration system. You can embed configuration hints directly in the module source file, or you can place them in separate files located in the same directory as the source file.

For the purposes of this example, we'll assume we're implementing a module named mod_compress which requires some of the data compression/decompression functions located in the system libz library. We need to arrange for -lz to be added to the LIBS makefile variable. One way to do this is to add the following comment somewhere toward the top of the source file mod_compress.c:

/* Module configuration hints
MODULE-DEFINITION-START
Name: compress_module
ConfigStart
  LIBS="$LIBS -lz"
  echo " + using -lz for compression support"
ConfigEnd
MODULE-DEFINITION-END
*/

When the configure script runs, it scans through a module looking for lines containing the MODULE-DEFINITION-START and MODULE-DEFINITION-END keywords and passes everything between the two lines to the configuration system. Within the configuration section, the Name: keyword specifies the name of the module, which should be the same as the name given in the ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.