今天在做东西的时候遇到一个问题,就是如何在C语言中调用C++做的动态链接库so文件如果你有一个c++做的动态链接库.so文件,而你只有一些相关类的声明, 那么你如何用c调用呢,别着急,本文通过一个小小的例子,让你能够很爽的搞定. 链接库头文件:head.h class A { public: A(); virtual ~A(); int gt(); int pt(); private: int s; }; // 何问起 hovertree.com firstso.cpp #include <
参考资料: http://www.linuxidc.com/Linux/2012-01/50739.htm http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html 1. -fpic Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine.
在dlopen()函数以指定模式打开指定的动态链接库文件,并返回一个句柄给dlsym()的调用进程.使用dlclose()来卸载打开的库. dlopen: dlopen() The function dlopen() loads the dynamic library file named by the null-terminated string filename and returns an opaque "handle" for the dynamic library. If f