.h
#ifndef __TESTDL
#define __TESTDL
#ifdef __cplusplus
extern "C"
{
#endif
int (*add)(int,int,int*);
//int addint(int,int,int*);
#ifdef __cplusplus
}
#endif
#endif
.c
//#include "testdl.h"
int addint(int a,int b,int* c){
*c = a + b;
return 0;
}
.c
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
//#include "testdl.h"
int main(int argc,char** argv){
void* handler;
int (*add)(int,int,int*);
int c = 0;
handler = dlopen("./testdl.so",RTLD_LAZY);
add = dlsym(handler,"addint");
add(1,2,&c);
printf("%d",c);
dlclose(handler);
return 0;
}
gcc -shared -fpic testdl.c -o testdl.so
gcc -ldl dltest.c -o dltest.exe
./dltest.exe