@@ -135,6 +135,10 @@ static void * dl_get_sym(dl_handle * handle, const char * name) {
135135 return p;
136136}
137137
138+ static const char * dl_error () {
139+ return " " ;
140+ }
141+
138142#else
139143
140144using dl_handle = void ;
@@ -155,6 +159,11 @@ static void * dl_get_sym(dl_handle * handle, const char * name) {
155159 return dlsym (handle, name);
156160}
157161
162+ static const char * dl_error () {
163+ const char *rslt = dlerror ();
164+ return rslt != nullptr ? rslt : " " ;
165+ }
166+
158167#endif
159168
160169using dl_handle_ptr = std::unique_ptr<dl_handle, dl_handle_deleter>;
@@ -240,7 +249,7 @@ struct ggml_backend_registry {
240249 dl_handle_ptr handle { dl_load_library (path) };
241250 if (!handle) {
242251 if (!silent) {
243- GGML_LOG_ERROR (" %s: failed to load %s\n " , __func__, path_str (path).c_str ());
252+ GGML_LOG_ERROR (" %s: failed to load %s: %s \n " , __func__, path_str (path).c_str (), dl_error ());
244253 }
245254 return nullptr ;
246255 }
@@ -530,7 +539,7 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
530539 if (filename.native ().find (file_prefix) == 0 && ext == file_extension) {
531540 dl_handle_ptr handle { dl_load_library (entry) };
532541 if (!handle && !silent) {
533- GGML_LOG_ERROR (" %s: failed to load %s\n " , __func__, path_str (entry.path ()).c_str ());
542+ GGML_LOG_ERROR (" %s: failed to load %s: %s \n " , __func__, path_str (entry.path ()).c_str (), dl_error ());
534543 }
535544 if (handle) {
536545 auto score_fn = (ggml_backend_score_t ) dl_get_sym (handle.get (), " ggml_backend_score" );
0 commit comments