diff --git a/Makefile b/Makefile index 5c8994385..bd2a79b93 100644 --- a/Makefile +++ b/Makefile @@ -290,6 +290,7 @@ endif # some memory allocation are available on Linux through GNU extensions in libc ifeq ($(UNAME_S),Linux) MK_CPPFLAGS += -D_GNU_SOURCE + MK_LDFLAGS += -ldl endif # RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1, diff --git a/ggml/src/CMakeLists.txt b/ggml/src/CMakeLists.txt index c506a413d..8cf2640fa 100644 --- a/ggml/src/CMakeLists.txt +++ b/ggml/src/CMakeLists.txt @@ -230,6 +230,10 @@ add_library(ggml target_link_libraries(ggml PUBLIC ggml-base) +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_link_libraries(ggml PRIVATE dl) +endif() + function(ggml_add_backend backend) string(TOUPPER "GGML_${backend}" backend_id) if (${backend_id}) diff --git a/ggml/src/ggml-backend-reg.cpp b/ggml/src/ggml-backend-reg.cpp index 78096af18..742b860bd 100644 --- a/ggml/src/ggml-backend-reg.cpp +++ b/ggml/src/ggml-backend-reg.cpp @@ -250,9 +250,14 @@ ggml_backend_reg_t ggml_backend_load(const char * path) { ggml_backend_reg_t reg = backend_init(); if (!reg) { GGML_LOG_ERROR("%s: failed to initialize backend from %s\n", __func__, path); +#ifdef _WIN32 + FreeLibrary(handle); +#else dlclose(handle); +#endif return nullptr; } + GGML_LOG_DEBUG("%s: loaded %s backend from %s\n", __func__, ggml_backend_reg_name(reg), path); get_reg().register_backend(reg, handle); return reg;