published on
tags: Computer Hack

Linking external libraries to an apache module

This is a straight translation from my qiita post in Japanese

You may want to link external libraries (like libmysqlclient) when you create an Apache module.

The Problem

So the Makefile generated by apxs includes some stub, which is like this:

# additional defines, includes and libraries #DEFS=-Dmy_define=my_value #INCLUDES=-Imy/include/dir #LIBS=-Lmy/lib/dir -lmylib

Cool, so I can add -lmysqlclient to LIBS, right? But the building command executed by make does not include -lmysqlclient, event after I add it.

What is worse, is that building the module itself succeeds somehow without the library, and I can only get an error when it is loaded into Apache.


The LIBS variable is referenced in /usr/share/apache2/build/ like ALL_LIBS = $(MOD_LIBS) $(EXTRA_LIBS) $(NOTEST_LIBS) $(LIBS), but this ALL_LIBS is never used anywhere.

So I can modify a bit, to properly use ALL_LIBS. Concretely, modify lines around # Link-related commands as below (ALL_LIBS is added after ALL_CFLAGS in SH_LINK):

# Link-related commands LINK = $(LIBTOOL) --mode=link $(CC) $(ALL_CFLAGS) $(PILDFLAGS) $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ # SH_LINK = $(SH_LIBTOOL) --mode=link $(CC) $(ALL_CFLAGS) $(LT_LDFLAGS) $(ALL_LDFLAGS) $(SH_LDFLAGS) $(CORE_IMPLIB) $(SH_LIBS) -o $@ SH_LINK = $(SH_LIBTOOL) --mode=link $(CC) $(ALL_CFLAGS) $(ALL_LIBS) $(LT_LDFLAGS) $(ALL_LDFLAGS) $(SH_LDFLAGS) $(CORE_IMPLIB) $(SH_LIBS) -o $@

It might be the case that you must add it somewhere else (like in BASE_CC or MOD_LINK), depending on what you want to use or how you build it.

Is it a bug of Apache?

So this issue (?) has existed since looooong time ago and is mentioned even in the Apache Users Mailing List.

So, ALL_LIBS isn’t getting used anywhere. Should it be in SH_LINK after $(ALL_LDFLAGS)?

I guess this is a bug of Apache… isn’t it???