#include <cstdio>
using namespace std;
extern "C"
{
extern void hello(void);
}
void
hello(void)
{
printf("void hello(void);\n");
}
g++ -c -fPIC hello.cpp
g++ -shared -lc -o hello.so hello.o
#include <dlfcn.h>
void (*func)(void);
int
main(int,char**)
{
void* handle(dlopen("./hello.so", RTLD_LAZY));
func = (void (*)(void))dlsym(handle,"hello");
func();
return 0;
}
g++ -o dltest dltest.cpp -ldl
댓글
댓글 쓰기