This commit is contained in:
2025-11-26 22:31:09 +01:00
parent 5023b63a7e
commit 28f0fdb520
7 changed files with 111 additions and 20 deletions

View File

@@ -11,7 +11,7 @@ extern "C" {
#include <direct.h>
#endif
#ifdef __linux
#if defined(__linux) || defined(TARGET_OS_OSX)
#include <dlfcn.h>
#endif
@@ -60,6 +60,33 @@ void GtkLoader::loadLibraryLinux(const char *lib, void **handle)
#endif
}
void GtkLoader::loadLibraryOSX(const char *lib, void **handle)
{
#ifdef TARGET_OS_OSX
std::string full_lib_path = std::string("/opt/homebrew/lib/") + lib;
*handle = ::dlopen(full_lib_path.c_str(), RTLD_LAZY);
if (*handle == NULL) {
throw std::string("Cannot load library '") + lib + "'";
}
#endif
}
void GtkLoader::loadFunctionOSX(const char *func, void **func_ptr)
{
#ifdef TARGET_OS_OSX
*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::loadFunctionWin64(const char *func, void **func_ptr)
{
#ifdef _WIN32
@@ -132,6 +159,23 @@ void GtkLoader::dlopen()
loadLibraryLinux(libs[i], &lib);
if (lib) { library_handles.push_back(lib); }
}
#endif
#ifdef TARGET_OS_OSX
const char *libs[] = {
"libgtk-3.0.dylib",
"libgobject-2.0.dylib",
"libgio-2.0.dylib",
"libglib-2.0.dylib",
"libgdk-3.dylib",
"libgdk_pixbuf-2.0.dylib",
NULL
};
int i;
for(i = 0; libs[i] != NULL; i++) {
void *lib;
loadLibraryOSX(libs[i], &lib);
if (lib) { library_handles.push_back(lib); }
}
#endif
}
}
@@ -144,6 +188,9 @@ void GtkLoader::loadFunction(const char *func, void **func_ptr)
#ifdef __linux
loadFunctionLinux(func, func_ptr);
#endif
#ifdef TARGET_OS_OSX
loadFunctionOSX(func, func_ptr);
#endif
}
static void loader(const char *func, void **func_ptr, void *user_data)