@@ -11,6 +11,10 @@ extern "C" {
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
void GtkLoader::loadLibraryWin64(const char *lib, void **handle)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -46,6 +50,16 @@ void GtkLoader::loadLibraryWin64(const char *lib, void **handle)
|
||||
#endif
|
||||
}
|
||||
|
||||
void GtkLoader::loadLibraryLinux(const char *lib, void **handle)
|
||||
{
|
||||
#ifdef __linux
|
||||
*handle = ::dlopen(lib, RTLD_LAZY);
|
||||
if (*handle == NULL) {
|
||||
throw std::string("Cannot load library '") + lib + "'";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GtkLoader::loadFunctionWin64(const char *func, void **func_ptr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -66,6 +80,22 @@ void GtkLoader::loadFunctionWin64(const char *func, void **func_ptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
void GtkLoader::loadFunctionLinux(const char *func, void **func_ptr)
|
||||
{
|
||||
#ifdef __linux
|
||||
*func_ptr = nullptr;
|
||||
std::list<void *>::const_iterator it = library_handles.begin();
|
||||
while(*func_ptr == nullptr && it != library_handles.end()) {
|
||||
void *handle = *it;
|
||||
*func_ptr = dlsym(handle, func);
|
||||
it++;
|
||||
}
|
||||
if (*func_ptr == nullptr) {
|
||||
throw std::string("Cannot load function '") + func;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GtkLoader::dlopen()
|
||||
{
|
||||
if (library_handles.size() == 0) {
|
||||
@@ -83,6 +113,22 @@ void GtkLoader::dlopen()
|
||||
loadLibraryWin64(libs[i], &lib);
|
||||
if (lib) { library_handles.push_back(lib); }
|
||||
}
|
||||
#endif
|
||||
#ifdef __linux
|
||||
const char *libs[] = {
|
||||
"libgtk-3.so",
|
||||
"libgobject-2.0.so",
|
||||
"libgio-2.0.so",
|
||||
"libglib-2.0.so",
|
||||
"libgdk-3.so",
|
||||
NULL
|
||||
};
|
||||
int i;
|
||||
for(i = 0; libs[i] != NULL; i++) {
|
||||
void *lib;
|
||||
loadLibraryLinux(libs[i], &lib);
|
||||
if (lib) { library_handles.push_back(lib); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -92,6 +138,9 @@ void GtkLoader::loadFunction(const char *func, void **func_ptr)
|
||||
#ifdef _WIN32
|
||||
loadFunctionWin64(func, func_ptr);
|
||||
#endif
|
||||
#ifdef __linux
|
||||
loadFunctionLinux(func, func_ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void loader(const char *func, void **func_ptr, void *user_data)
|
||||
|
||||
Reference in New Issue
Block a user