link to libdl on linux

This commit is contained in:
slaren 2024-11-24 01:08:56 +01:00
parent ccd8df8a9d
commit 1605605b54
3 changed files with 10 additions and 0 deletions

View File

@ -290,6 +290,7 @@ endif
# some memory allocation are available on Linux through GNU extensions in libc # some memory allocation are available on Linux through GNU extensions in libc
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
MK_CPPFLAGS += -D_GNU_SOURCE MK_CPPFLAGS += -D_GNU_SOURCE
MK_LDFLAGS += -ldl
endif endif
# RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1, # RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,

View File

@ -230,6 +230,10 @@ add_library(ggml
target_link_libraries(ggml PUBLIC ggml-base) 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) function(ggml_add_backend backend)
string(TOUPPER "GGML_${backend}" backend_id) string(TOUPPER "GGML_${backend}" backend_id)
if (${backend_id}) if (${backend_id})

View File

@ -250,9 +250,14 @@ ggml_backend_reg_t ggml_backend_load(const char * path) {
ggml_backend_reg_t reg = backend_init(); ggml_backend_reg_t reg = backend_init();
if (!reg) { if (!reg) {
GGML_LOG_ERROR("%s: failed to initialize backend from %s\n", __func__, path); GGML_LOG_ERROR("%s: failed to initialize backend from %s\n", __func__, path);
#ifdef _WIN32
FreeLibrary(handle);
#else
dlclose(handle); dlclose(handle);
#endif
return nullptr; return nullptr;
} }
GGML_LOG_DEBUG("%s: loaded %s backend from %s\n", __func__, ggml_backend_reg_name(reg), path); GGML_LOG_DEBUG("%s: loaded %s backend from %s\n", __func__, ggml_backend_reg_name(reg), path);
get_reg().register_backend(reg, handle); get_reg().register_backend(reg, handle);
return reg; return reg;