Mehdi Homeyli
Mehdi Homeyli

Reputation: 409

how to dlopen so file in apache module development with apxs

I'm trying open a so file in apache module with this code :

#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
   };

i'm included dlfcn.h header file but not work! compiling with this : apxs -i -a -c mod_helloworld.c i'm trying compile with -ldl : apxs -i -a -c Wc,-ldl mod_helloworld.c but don't working. i have this error in dlerror() : /usr/lib/apache2/modules/mod_helloworld.so: undefined symbol: echo

Upvotes: 0

Views: 323

Answers (0)

Related Questions