简体   繁体   English

自定义 apache2 模块将不会加载并显示错误消息“找不到 API 模块结构”

[英]custom apache2 module will not load with error message "Can't locate API module structure"

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]我是一名 Windows 开发人员,但现在正尝试使用 apxs2 工具在 linux 上构建一个非常简单的 apache2 模块,如本文所述:[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". Apache 在重新启动时发出以下错误:“找不到 API 模块结构”。

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'"它失败并显示错误消息“无法确定引导程序符号名称”并且必须“使用选项‘-n’指定一个”

When option -n is supplied the module is being successfully built:当提供选项 -n 时,模块正在成功构建:

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

But an attempt to restart apache issues following error:但是尝试重新启动 apache 会出现以下错误:

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. apache2:/etc/apache2/apache2.conf 第 203 行的语法错误:/etc/apache2/mods-enabled/pixmongo.load 第 1 行的语法错误:无法在文件 /usr 中找到 API 模块结构“pixmongo_module” /lib/apache2/modules/mod_pixmongo.so: /usr/lib/apache2/modules/mod_pixmongo.so: undefined symbol: pixmongo_module 动作 'configtest' 失败。

I know little about shared libraries on linux but suggest that the module structure must be somehow exported.我对 linux 上的共享库知之甚少,但建议必须以某种方式导出模块结构。 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:头文件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:源文件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

I realized my mistake.我意识到我的错误。 Utility apxs is not capable to build C++ modules but only C (the latter worked fine for me).实用程序 apxs 不能构建 C++ 模块,只能构建 C(后者对我来说工作得很好)。 In the above mentioned codeproject article the apxs utility is only used to deploy already compiled module but not to compile it.在上面提到的 codeproject 文章中,apxs 实用程序仅用于部署已编译的模块,而不用于编译它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM