From b70d60fd78f33c3ae343dc711e9a6cbda5a66c8e Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 13 Mar 2025 13:05:01 +0100 Subject: [PATCH 1/3] examples : add dl to the list of libraries linked This commit adds the dynamic linker library to the list of libraries linked by the examples. The motivation for this change is that when building the examples on ubuntu 20.04, which uses GCC 9.4.0, the dynamic linker requires explicit linking or the following error is generated: ```console [ 64%] Linking CXX executable ../../bin/whisper-cli cd /app/whisper.cpp/build/examples/cli && /usr/bin/cmake -E cmake_link_script CMakeFiles/whisper-cli.dir/link.txt --verbose=1 /usr/bin/c++ -O3 -DNDEBUG CMakeFiles/whisper-cli.dir/cli.cpp.o -o ../../bin/whisper-cli -Wl,-rpath,/app/whisper.cpp/build/src:/app/whisper.cpp/build/ggml/src: ../libcommon.a ../../src/libwhisper.so.1.7.4 -pthread ../../ggml/src/libggml.so ../../ggml/src/libggml-cpu.so ../../ggml/src/libggml-base.so /usr/bin/ld: ../libcommon.a(common-whisper.cpp.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' /usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status make[2]: *** [examples/cli/CMakeFiles/whisper-cli.dir/build.make:89: bin/whisper-cli] Error 1 make[2]: Leaving directory '/app/whisper.cpp/build' make[1]: *** [CMakeFiles/Makefile2:433: examples/cli/CMakeFiles/whisper-cli.dir/all] Error 2 make[1]: Leaving directory '/app/whisper.cpp/build' make: *** [Makefile:130: all] Error 2 ``` Refs: https://github.com/ggerganov/whisper.cpp/issues/2854 --- examples/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e1b083d352b..c8deec1c89f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -61,7 +61,7 @@ add_library(${TARGET} STATIC include(DefaultTargetOptions) -target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS}) +target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS} dl) set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${TARGET} PROPERTIES FOLDER "libs") From 23fbfe965cfd20ed98746c0bf26ab2ef67b6cef2 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 13 Mar 2025 13:23:04 +0100 Subject: [PATCH 2/3] squash! examples : add dl to the list of libraries linked Add guard to only link dl on non-Apple Unix systems. --- examples/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c8deec1c89f..da4992e70a5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -61,7 +61,11 @@ add_library(${TARGET} STATIC include(DefaultTargetOptions) -target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS} dl) +if(UNIX AND NOT APPLE) + target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS} dl) +else() + target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS}) +endif() set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${TARGET} PROPERTIES FOLDER "libs") From 951933b3f92d6c019994a746703ff8f1019ba624 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 13 Mar 2025 18:07:53 +0100 Subject: [PATCH 3/3] squash! examples : add dl to the list of libraries linked Use CMAKE_DL_LIBS instead using if statement to link dl library on Unix systems. --- examples/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index da4992e70a5..e4265affe97 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -61,11 +61,7 @@ add_library(${TARGET} STATIC include(DefaultTargetOptions) -if(UNIX AND NOT APPLE) - target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS} dl) -else() - target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS}) -endif() +target_link_libraries(${TARGET} PRIVATE whisper ${COMMON_EXTRA_LIBS} ${CMAKE_DL_LIBS}) set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${TARGET} PROPERTIES FOLDER "libs")