2

i have wrote the c++ module in apache. The following is the code ::

mod_foo.hpp

#ifndef MOD_FOO_HPP
#define MOD_FOO_HPP
#ifdef __cplusplus
#define EXTERN_C_BLOCK_BEGIN    extern "C" {
#define EXTERN_C_BLOCK_END      }
#define EXTERN_C_FUNC           extern "C"
#else
#define EXTERN_C_BLOCK_BEGIN
#define EXTERN_C_BLOCK_END
#define EXTERN_C_FUNC
#endif
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>**
#endif  /* MOD_FOO_HPP */

mod_foo.c

#include "mod_foo.hpp"

EXTERN_C_FUNC
int foo_handler( request_rec* inpRequest )
{
    int nReturnVal = DECLINED;

    if ( inpRequest->handler != NULL && strcmp( inpRequest->handler, "foo" ) == 0 )
    {
        ap_rputs( "Hello World from FOO", inpRequest );
        nReturnVal = OK;
    }

    return nReturnVal;
}

EXTERN_C_FUNC
void foo_hooks( apr_pool_t* inpPool )
{
    ap_hook_handler( foo_handler, NULL, NULL, APR_HOOK_MIDDLE );
}

EXTERN_C_BLOCK_BEGIN
module AP_MODULE_DECLARE_DATA foo_module =
{
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    foo_hooks
};
EXTERN_C_BLOCK_END

The module is compiling successfully and it's also installing on the apache server but when i restart the apache server after installing it The following Error occurs:

apache2: Syntax error on line 234 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/conf.d/foo.conf: API module structure 'foo_module' in file /usr/lib/apache2/modules/mod_foo.so is garbled - expected signature 41503232 but saw 41503234 - perhaps this is not an Apache module DSO, or was compiled for a different Apache version?

I added the LoadModule thing in httpd.conf to load the module but only c++ modules is giving this error. Any idea about how to resolve this problem?

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • You and [this question author](http://stackoverflow.com/questions/14892540/custom-apache2-module-will-not-load-with-error-message-cant-locate-api-module) could probably share notes. Is this for some class? – WhozCraig Feb 15 '13 at 14:21

1 Answers1

0

I think the handler should be declared as static, this could cause fault, beside that you should add a prefix extern "C" in front of the module, but adding every function with a extern "C" prefix is unnecessary.

Matthewgao
  • 281
  • 1
  • 4
  • 12