M
Matt Churchyard
Now I realize this is off topic, and will probably quickly receive a list
of replys from people who are quicker to criticize posters than give them
help but if you know of a more suitable newsgroup i will be happy to go
there instead.
I am using the dlopen,dlsym functions to load in an external module in my
program
which works fine. I can call functions inside the loaded module and all is
well.
The problem is, when i try and call a function inside the main program from
the module,
it won't load giving 'Undefined symbol "getnumber"' errors. I can think of
no way round this.
Below is the test program I am using.
load.c
----------------------------------------------------------------------------
#include <stdio.h>
#include <dlfcn.h>
#include "load.h"
typedef int (*pointer)();
int main(void)
{
void *modhandle;
pointer symhandle;
modhandle = dlopen("./testmod.so", RTLD_LAZY);
if( modhandle == NULL )
{
printf("Load failed \"%s\"\n", dlerror());
exit(1);
}
symhandle = (pointer)dlsym(modhandle, "testfunc");
if( symhandle == NULL )
{
printf("Sym failed \"%s\"\n", dlerror());
exit(1);
}
(*symhandle)();
dlclose(modhandle);
}
int getnumber()
{
return 10;
}
----------------------------------------------------------------------------
load.h
----------------------------------------------------------------------------
int getnumber();
----------------------------------------------------------------------------
testmod.c
----------------------------------------------------------------------------
#include <stdio.h>
#include "load.h"
int testfunc()
{
int i;
i = getnumber();
printf("Hello %d\n", i);
}
----------------------------------------------------------------------------
--
Regards,
Matt Churchyard
_______________________________
Project Development Manager
Userve Internet
(e-mail address removed)
http://www.userve.net/
of replys from people who are quicker to criticize posters than give them
help but if you know of a more suitable newsgroup i will be happy to go
there instead.
I am using the dlopen,dlsym functions to load in an external module in my
program
which works fine. I can call functions inside the loaded module and all is
well.
The problem is, when i try and call a function inside the main program from
the module,
it won't load giving 'Undefined symbol "getnumber"' errors. I can think of
no way round this.
Below is the test program I am using.
load.c
----------------------------------------------------------------------------
#include <stdio.h>
#include <dlfcn.h>
#include "load.h"
typedef int (*pointer)();
int main(void)
{
void *modhandle;
pointer symhandle;
modhandle = dlopen("./testmod.so", RTLD_LAZY);
if( modhandle == NULL )
{
printf("Load failed \"%s\"\n", dlerror());
exit(1);
}
symhandle = (pointer)dlsym(modhandle, "testfunc");
if( symhandle == NULL )
{
printf("Sym failed \"%s\"\n", dlerror());
exit(1);
}
(*symhandle)();
dlclose(modhandle);
}
int getnumber()
{
return 10;
}
----------------------------------------------------------------------------
load.h
----------------------------------------------------------------------------
int getnumber();
----------------------------------------------------------------------------
testmod.c
----------------------------------------------------------------------------
#include <stdio.h>
#include "load.h"
int testfunc()
{
int i;
i = getnumber();
printf("Hello %d\n", i);
}
----------------------------------------------------------------------------
--
Regards,
Matt Churchyard
_______________________________
Project Development Manager
Userve Internet
(e-mail address removed)
http://www.userve.net/