lkml.org 
[lkml]   [1997]   [Jun]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [off-topic] Loadable modules
Date
Thank you everyone. libdl does exactly what I want, much more neatly than I
had hoped for (although I should have expected this from Linux :-)

Cheers,

Brian.

(short example attached)

:::::::: wibble.c
#include <stdio.h>

void entry(void)
{
printf("Hello, world!\n");
}

:::::::: main.c
#include <dlfcn.h>
#include <stdio.h>

int main(void)
{
const char *e;
void (*p)();

void *h = dlopen("./wibble.o", RTLD_NOW);
if (!h) {
printf("Failed: %s\n", dlerror());
return 1;
}
p = dlsym(h, "entry");
e = dlerror();
if (e) {
printf("Failed(2): %s\n", e);
return 1;
}
p();
dlclose(h);
return 0;
}

Compile like this:

gcc -Wall main.c -o main -ldl
gcc -Wall -shared wibble.c -o wibble.o
./main

\
 
 \ /
  Last update: 2005-03-22 13:39    [W:0.050 / U:1.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site