Linux下动态库的使用

来源:互联网 发布:红米note4双卡网络 编辑:程序博客网 时间:2024/06/15 06:37

 

reader.cpp //This cpp build libreader.so, use tt.so


#include <dlfcn.h>

typedef int( *Fun_OpenReader)( int ReaderType, char *DeviceID, char *Password );

int *g_hModule;
Fun_OpenReader libOpen = NULL;

g_hModule = (int *)dlopen( "./tt.so", 1 ); //load dll (tt.so: others )
libOpen = (Fun_OpenReader)dlsym( g_hModule, "OpenReader" ); //func address
dlclose( g_hModule ); //free dll


g++ reader.cpp -o libreader.so -fpic -shared

 


==================================================
test.cpp  //this cpp use libreader.so

g++ test.cpp -o a.out -ldl  

 

原创粉丝点击