On Thu, May 2, 2013 at 6:46 PM, oneat <[email protected]> wrote:
> Do you have any other samples for cpp coding for httpd? I heard about codea,
> but it seems a bit outdated.
apxs doesn't really understand how to deal with C++ modules, to get
this to work correctly I needed to write a Makefile:
APXS=apxs
APXS_CFLAGS:=`$(APXS) -q CFLAGS`
APXS_CFLAGS_SHLIB:=`$(APXS) -q CFLAGS_SHLIB`
APXS_INCLUDEDIR:=`$(APXS) -q INCLUDEDIR`
APXS_LIBS_SHLIB:=`$(APXS) -q LIBS_SHLIB`
APR_INCLUDES:=`apr-1-config --includes`
all: mod_cpp.so
mod_cpp.o: mod_cpp.cpp
g++ -c -fPIC -I$(APXS_INCLUDEDIR) -I. $(APR_INCLUDES)
$(APXS_CFLAGS) $(APXS_CFLAGS_SHLIB) -Wall -o $@ $<
mod_cpp.so: mod_cpp.o
g++ -fPIC -shared -o $@ $< $(APXS_LIBS_SHLIB)
clean:
rm -rf *.o *.so
With that, simply follow the instructions I gave you earlier - give C
linkage to the module and declare it extern:
#include "httpd.h"
#include "http_core.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
extern "C" module cpp_module;
static int handle(request_rec *r)
{
ap_set_content_type(r, "text/html");
ap_rprintf(r, r->filename);
return HTTP_OK;
}
static void register_hooks(apr_pool_t *pool)
{
/* Create a hook in the request handler, so we get called when a
request arrives */
ap_hook_handler(handle, NULL, NULL, APR_HOOK_LAST);
}
extern "C" {
module AP_MODULE_DECLARE_DATA cpp_module =
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
};
Cheers
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]