我正在尝试使用以下代码在 apache 模块中打开一个 so 文件:
#include <dlfcn.h>
#include <stdbool.h>
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
static int helloworld_handler(request_rec* r)
{
if (!r->handler || strcmp(r->handler, "helloworld"))
return DECLINED;
if (r->method_number != M_GET)
return HTTP_METHOD_NOT_ALLOWED;
// here i try to load so file --------------------------------
typedef bool (*hello_t)();
void *handle;
handle = dlopen ("/lib.so", RTLD_LAZY);
hello_t echo = (hello_t) dlsym(handle, "echo");
echo();
// ------------------------------------------------------------
return OK;
}
static void register_hooks(apr_pool_t* pool)
{
ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA helloworld_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
我包含 dlfcn.h 头文件但不起作用!用这个编译:apxs -i -a -c mod_helloworld.c 我正在尝试用 -ldl 编译:apxs -i -a -c Wc,-ldl mod_helloworld.c 但不工作。我在 dlerror() 中有这个错误:/usr/lib/apache2/modules/mod_helloworld.so: undefined symbol: echo