I'm trying to load all the libraries, and call a function from each one, to create a file and shate the fiddle thru the pointer, and write stuff in the main program with them, the close them.
This is my main function:
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
char LIBA[]="./LIBA.SO";
char LIBB[]="./LIBB.SO";
char LIBC[]="./LIBC.SO";
typedef void (*FUNC_T)(int*);
FUNC_T FUNC[2];
void ifnull(void *detect)
{
if (detect == NULL)
{
cout << "ERROR:" << dlerror() << endl;
exit(-1);
}
}
void ifnull2(FUNC_T detect)
{
if (detect == NULL)
{
cout << "ERROR:" << dlerror() << endl;
exit(-1);
}
}
int main()
{
void *handle[2];
int FD[2];
handle[0]=dlopen(LIBA, RTLD_LAZY); ifnull(handle[0]);
handle[1]=dlopen(LIBB, RTLD_NOW); ifnull(handle[1]);
handle[2]=dlopen(LIBC, RTLD_NOW); ifnull(handle[2]);
FUNC[0]=(void(*)(int*))dlsym(handle[0], "c"); ifnull2(FUNC[0]);
FUNC[1]=(void(*)(int*))dlsym(handle[1], "c"); ifnull2(FUNC[1]);
FUNC[2]=(void(*)(int*))dlsym(handle[2], "c"); ifnull2(FUNC[2]);
FUNC[0](&FD[0]); FUNC[1](&FD[1]); FUNC[2](&FD[2]);
return 0;
}
This is inside the libs:
#include <stdio.h>
void c(int *fd)
{
printf("ok A\n");
}
I keep getting
ERROR:./LIBA.SO: undefined symbol: c
please help