File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -25,13 +25,37 @@ namespace appimage {
2525 * @param libName
2626 * @param mode
2727 */
28- explicit DLHandle (const std::string& libName, int mode) : libName(libName) {
28+ explicit DLHandle (const std::string& libName, int mode) : handle( nullptr ), libName(libName) {
2929 handle = dlopen (libName.c_str (), mode);
3030
31- if (! handle)
31+ if (handle == nullptr )
3232 throw DLHandleError (" Unable to load " + libName);
3333 }
3434
35+ /* *
36+ * Load one of the libraries listed in <libNames> with the given <mode> flags. For details about
37+ * the allowed flags see the dlopen doc.
38+ * @param libName
39+ * @param mode
40+ */
41+ explicit DLHandle (std::initializer_list<const std::string> libNames, int mode) : handle(nullptr ) {
42+ for (const auto & item: libNames) {
43+ handle = dlopen (item.c_str (), mode);
44+ if (handle != nullptr ) {
45+ libName = item;
46+ break ;
47+ }
48+ }
49+
50+ if (handle == nullptr ) {
51+ std::string libNamesStr;
52+ for (const auto & item: libNames)
53+ libNamesStr += " " + item;
54+
55+ throw DLHandleError (" Unable to load any of: " + libNamesStr);
56+ }
57+ }
58+
3559 virtual ~DLHandle () {
3660 dlclose (handle);
3761 };
Original file line number Diff line number Diff line change @@ -224,14 +224,18 @@ namespace appimage {
224224 g_object_unref_t object_unref = nullptr ;
225225
226226 /* *
227- * @brief Load libgobject-2.0.so and resolve the symbol addresses required by the IconHandle.
227+ * @brief Load libgobject-2 and resolve the symbol addresses required by the IconHandle.
228+ *
229+ * Known library name by distribution:
230+ * - CentOS: libgobject-2.0.so.0
231+ * - Debian/Ubuntu: libgobject-2.0.so
228232 *
229233 * Mode comments:
230234 * RTLD_LAZY - load the lib only the required symbols
231235 * RTLD_NODELETE - do not unload the lib, as it wasn't designed to be used this way it
232236 * will produce a big crash.
233237 */
234- GLibOjbectHandle () : DLHandle(" libgobject-2.0.so" , RTLD_LAZY | RTLD_NODELETE) {
238+ GLibOjbectHandle () : DLHandle({ " libgobject-2.0.so" , " libgobject-2.0.so.0 " } , RTLD_LAZY | RTLD_NODELETE) {
235239 DLHandle::loadSymbol (object_unref, " g_object_unref" );
236240 }
237241 };
You can’t perform that action at this time.
0 commit comments