class A { public: A(); virtual ~A(); int gt(); int pt(); private: int s; };
#include <iostream> #include "head.h" A::A(){} A::~A(){} int A::gt() { s=10; } int A::pt() { std::cout<<s<<std::endl; }
#include <iostream> #include "head.h" extern "C" { int f(); int f() { A a; a.gt(); a.pt(); return 0; } }
#include "stdio.h" #include "dlfcn.h" #define SOFILE "sec.so" int (*f)(); int main() { void *dp; dp=dlopen(SOFILE,RTLD_LAZY); f=dlsym(dp,"f"); f(); return 0; }
运行Z$./myapp
10