reductions, build fixes
This commit is contained in:
parent
ff11966791
commit
12f03e20c4
@ -1,4 +1,4 @@
|
||||
CFLAGS += -shared -fPIE
|
||||
CFLAGS += -shared -fPIC
|
||||
|
||||
libplug.so: plug.o
|
||||
${LINK.c} $+ -o $@
|
||||
|
@ -1,10 +1,12 @@
|
||||
#ifndef PLUG_H_
|
||||
|
||||
#define _QUOTE(name) #name
|
||||
#define QUOTE(name) _QUOTE(name)
|
||||
#define BIND(lib, func, func_name) *(void **) (&func) = dlsym(lib, func_name)
|
||||
#define PLUGIN(lib, x) BIND(lib, x, QUOTE(x))
|
||||
|
||||
typedef void (*plug_t)(void);
|
||||
|
||||
static plug_t plug;
|
||||
plug_t plug;
|
||||
|
||||
#define PLUG_H_
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
CPPFLAGS += -I../plug -L../plug
|
||||
LDLIBS += -ldl
|
||||
|
||||
plugin: main.o
|
||||
${LINK.c} $+ -o $@ ${LDLIBS}
|
||||
|
@ -12,19 +12,18 @@ main (void)
|
||||
void * libplug = NULL;
|
||||
while (1)
|
||||
{
|
||||
if (libplug) { dlclose(libplug); }
|
||||
libplug = dlopen(libplug_fn, RTLD_NOW);
|
||||
BIND(libplug, plug, "plug");
|
||||
if (!libplug)
|
||||
{ fprintf(stderr, "ERR: Cannot load dynamic library %s: %s\n", libplug_fn, dlerror()); }
|
||||
else
|
||||
{
|
||||
*(void **) (&plug) = dlsym(libplug, "plug");
|
||||
PLUGIN(libplug, plug);
|
||||
printf("frame %d: ", x++);
|
||||
if (plug)
|
||||
{ plug(); }
|
||||
else
|
||||
{ fprintf(stderr, "ERR: Cannot find %s symbol in %s: %s\n", "plug", libplug_fn, dlerror()); }
|
||||
dlclose(libplug);
|
||||
}
|
||||
sleep(2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user