…just another hippy blog

Software development, cold beer, photography and other high-caffeine, bikini powered, topics.

Untitled post about wynona’s puppet

Coffee … break !
Originally uploaded by Christiane Michaud.

Sorry folks, I was lying. This post is not about wynona. I’m really really sorry.
I have spent the whole day trying to build an apache module using Qt and qmake so I have to blog about my success.

I know, the guys at apache (btw. I’m really impressed by their work) advise against writing C++ modules or linking shared libraries, but I’ll have to do that for a project I’m working on at Clickout Ltd. so we’ll have to discuss those issues some day.

Nevertheless, the traditional mod_helloworld buit with no hassle on windows but there was no way to make it work on Linux/GCC so I had quite some fun figuring out the issue. So, here is a quick tutorial :-)

For starters, you’ll need to setup your Qt project to build either a dll or a plugin. I used the latter so I won’t have all those symlinks typical for *nix libraries.
The you’ll need to get it to work is add the path to your system’s apache2 and apr-1.0 header files to the includepath:

INCLUDEPATH += /usr/include/apr-1.0
INCLUDEPATH += /usr/include/apache2

Now comes the tricky part. Qt will usually tell g++ to report undefined references in object files by passing the -Wl,–no-undefined parameter to the linker.
It took me hours to realize that this was the issue. Apache modules are usually built using a C compiler and libtool or even the apxs[2] Apache perl script that does all the stuff for you.

It also took me some time to figure why I was not succeeding in removing that –no-undefined flag using the QMAKE* variables. So, this is what I came up with after reading the g++ mkspec source code:

QMAKE_LFLAGS -= -Wl,–no-undefined

Now, I am pretty sure I tried QMAKE_LFLAGS before and it would not work, but well you know how these things work.
So, this will build a file called libTARGET_NAME.so.
Now follow the usual steps to install it and restart apache ;-)

You can take the helloworld module source code from here:
http://www.cb1inc.com/2007/12/24/creating-a-hello-world-apache-module-with-kdevelop-on-ubuntu

then just add some QString and whatever else ;-)

UPDATE: Apache 2.x will disable strtoul from the C standard library but your MS VC compiler is very likely to use it, so you will get some error with strtoul_is_not_a_portable_function_use_strtol_instead. Just add an #undef strtoul *after* #including httpd.h and *before* #including any code that might use the cstdlib, like QString.

2 Comments so far

  1. Evan Reynolds May 28th, 2008 4:05 pm

    #undef strtoul huh?

    Thank you so much for posting this! I’ve been struggling with this for several hours and am really pleased to have read this on your blog!

  2. hippydream May 28th, 2008 4:39 pm

    Well, I’m glad it could be of some help.
    I spent a whole morning to figure this out ;-)

Leave a reply