File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
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
3131 if (!handle)
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) {
45+ libName = item;
46+ break ;
47+ }
48+ }
49+
50+ if (!handle) {
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 };
You can’t perform that action at this time.
0 commit comments