custom apache2 module will not load with error message “Can't locate API module structure”

我只是一个虾纸丫 提交于 2019-12-11 10:09:25

问题


I'm a windows developer but now trying to build a very simple apache2 module on linux using apxs2 tool as described in this article: [http://www.codeproject.com/Articles/491909/Apache-2-x-Modules-In-Cplusplus-Part-1][1]

The module is being successfully build but cannot be loaded for some reason. Apache issues following error on restart: "Can't locate API module structure".

Now some details.

First of all trying to build the module with following command

 apxs2 -i -a  -c mod_pixmongo.cpp

It fails with error message that it "cannot determine bootstrap symbol name" and that one must "specify one with option `-n'"

When option -n is supplied the module is being successfully built:

apxs2 -i -a -n pixmongo  -c mod_pixmongo.cpp

But an attempt to restart apache issues following error:

apache2: Syntax error on line 203 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/pixmongo.load: Can't locate API module structure `pixmongo_module' in file /usr/lib/apache2/modules/mod_pixmongo.so: /usr/lib/apache2/modules/mod_pixmongo.so: undefined symbol: pixmongo_module Action 'configtest' failed.

I know little about shared libraries on linux but suggest that the module structure must be somehow exported. Following command in my understanding is supposed to show exported symbols:

nm -D /usr/lib/apache2/modules/mod_pixmongo.so

In my case it shows following:

w _Jv_RegisterClasses
0000000000200778 A __bss_start
             w __cxa_finalize
             w __gmon_start__
0000000000200778 A _edata
0000000000200788 A _end
0000000000000558 T _fini
0000000000000418 T _init

So the structure "module" is really not there and I find it pretty strange. To compare: any other pre-installed module have that structure exported. For example:

nm -D /usr/lib/apache2/modules/mod_info.so

w _Jv_RegisterClasses
00000000002052b0 A __bss_start
             w __cxa_finalize
             w __gmon_start__
00000000002052b0 A _edata
00000000002052c0 A _end
0000000000002b48 T _fini
0000000000001708 T _init
************** the long list here *********
00000002050e0 D info_module
             U strcasecmp
             U strcmp

So the question is what I'm doing wrong. Any help is very much appreciated. The source code of the sample module is below:

Header file mod_pixmongo.hpp:

#ifndef MOD_PIXMONGO_HPP
#define MOD_PIXMONGO_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_PIXMONGO_HPP */

Source file mod_pixmongo.cpp:

#include "mod_pixmongo.hpp"

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

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

return nReturnVal;
}

EXTERN_C_FUNC
void pixmongo_hooks( apr_pool_t* inpPool )
{
ap_hook_handler( pixmongo_handler, NULL, NULL, APR_HOOK_MIDDLE );
}

EXTERN_C_BLOCK_BEGIN
module AP_MODULE_DECLARE_DATA pixmongo_module =
{
  STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
pixmongo_hooks
};
EXTERN_C_BLOCK_END

回答1:


I realized my mistake. Utility apxs is not capable to build C++ modules but only C (the latter worked fine for me). In the above mentioned codeproject article the apxs utility is only used to deploy already compiled module but not to compile it.



来源:https://stackoverflow.com/questions/14892540/custom-apache2-module-will-not-load-with-error-message-cant-locate-api-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!