标签:
linux 通过dlopen来实现:
#include "polygon.h" #include <stdlib.h> #include <dlfcn.h> int main() { typedef CPolygon* create_t(); void * handle = dlopen("./triangle.so", RTLD_LAZY); if( !handle ) { std::cerr << dlerror() << std::endl; exit(1); } create_t * create_triangle = (create_t *)dlsym(handle, "create"); CPolygon * pObj = create_triangle(); if( 0 != pObj ) { pObj->area(); } delete pObj; dlclose(handle); return 0; }
生成动态库:g++ -fPIC -shared triangle.cpp -o triangle.so
生成test主函数:g++ -fPIC test.cpp -ldl -o test
具体demo:http://files.cnblogs.com/files/hero4china/plugins_1.zip
参考:
https://my.oschina.net/u/1450061/blog/204564
https://my.oschina.net/u/1450061/blog/204608
https://my.oschina.net/u/1450061/blog/204563
标签:
原文地址:http://www.cnblogs.com/hero4china/p/5898252.html