C++代码 动态加载库

动态加载库

Win

HMODULE hmodule = LoadLibrary("my.dll");
Func fun = (Func)GetProcAddress(hmodule, "func");
FreeLibrary(hmodule);

linux (编译参数 -rdynamic -ldl )

hmodule = dlopen("my.so", RTLD_LAZY);
Func fun = (Func)dlsym(hmodule, "func");
dlclose(handle);

mac

linux mac
hmodule = dlopen("my.dylib", RTLD_GLOBAL);
Func fun = (Func)dlsym(hmodule, "func");
dlclose(hmodule);

你可能感兴趣的:(标准C++)