Search code examples
cmakeshared-librariesopenai-whisperrpathcmakelists-options

CMake : error while loading shared libraries: libwhisper.so.1: cannot open shared object file: No such file or directory


I installed whisper in MyPrj :

~/Downloads/whisper.cpp$ cmake --install builddir/ --prefix=/home/me/MyPrj/src/whisperLib
-- Install configuration: "Release"
-- Installing: /home/me/MyPrj/src/whisperLib/lib/libwhisper.so.1.7.4
-- Installing: /home/me/MyPrj/src/whisperLib/lib/libwhisper.so.1
-- Set non-toolchain portion of runtime path of "/home/me/MyPrj/src/whisperLib/lib/libwhisper.so.1.7.4" to ""
-- Installing: /home/me/MyPrj/src/whisperLib/lib/libwhisper.so
-- Installing: /home/me/MyPrj/src/whisperLib/include/whisper.h
-- Installing: /home/me/MyPrj/src/whisperLib/lib/cmake/whisper/whisper-config.cmake
-- Installing: /home/me/MyPrj/src/whisperLib/lib/cmake/whisper/whisper-version.cmake
-- Installing: /home/me/MyPrj/src/whisperLib/lib/pkgconfig/whisper.pc
-- Installing: /home/me/MyPrj/src/whisperLib/lib/libggml-cpu.so
-- Set non-toolchain portion of runtime path of "/home/me/MyPrj/src/whisperLib/lib/libggml-cpu.so" to ""
-- Installing: /home/me/MyPrj/src/whisperLib/lib/libggml.so
-- Set non-toolchain portion of runtime path of "/home/me/MyPrj/src/whisperLib/lib/libggml.so" to ""
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-cpu.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-alloc.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-backend.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-blas.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-cann.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-cuda.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-kompute.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-opt.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-metal.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-rpc.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-sycl.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/ggml-vulkan.h
-- Installing: /home/me/MyPrj/src/whisperLib/include/gguf.h
-- Installing: /home/me/MyPrj/src/whisperLib/lib/libggml-base.so
-- Installing: /home/me/MyPrj/src/whisperLib/bin/whisper-cli
-- Set non-toolchain portion of runtime path of "/home/me/MyPrj/src/whisperLib/bin/whisper-cli" to ""
-- Installing: /home/me/MyPrj/src/whisperLib/bin/whisper-bench
-- Set non-toolchain portion of runtime path of "/home/me/MyPrj/src/whisperLib/bin/whisper-bench" to ""
-- Installing: /home/me/MyPrj/src/whisperLib/bin/whisper-server
-- Set non-toolchain portion of runtime path of "/home/me/MyPrj/src/whisperLib/bin/whisper-server" to ""


/MyPrj/src/whisperLib$ ls
bin  include  lib

/MPrj/srs/whisperLib$ ls ./lib/
cmake            libggml-cpu.so  libwhisper.so    libwhisper.so.1.7.4
libggml-base.so  libggml.so      libwhisper.so.1  pkgconfig

in CMakeLists.txt I've put :

add_library(libwhisper SHARED IMPORTED)
set_target_properties(libwhisper PROPERTIES
    IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/src/whisperLib/lib/libwhisper.so"
    IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/src/whisperLib/lib/libwhisper.so.1"
    IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/src/whisperLib/lib/libwhisper.so.1.7.4"
    INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src/whisperLib/include"

    target_link_libraries(whisper)
)

But executing I get :

error while loading shared libraries: libwhisper.so.1: cannot open shared object file: No such file or directory

Update 1) Following the indications found here: How to set RPATH in CMAKE? ( thanks @Tsyvarev) I tried to specify the RPATH as follows, but, still :

libwhisper.so.1: cannot open shared object file: No such file or  
directory

:

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
add_library(libwhisper SHARED IMPORTED)
set(RPATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib/libwhisper.so.1")
set_target_properties(libwhisper PROPERTIES
    IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/src/whisperLib/lib/libwhisper.so.1"
    INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src/whisperLib/include"

    target_link_libraries(whisper)
    LINK_FLAGS "-Wl,-rpath,${RPATH}"
)

Update 2) :

So far I've tried the following suggestions taken from here: How to set RPATH in CMAKE? and from here: How do I add a library path in cmake? For each suggestion I tried to set the path to the file: ${CMAKE_SOURCE_DIR}/src/whisperLib/lib/libwhisper.so.1" and then to the folder: ${CMAKE_SOURCE_DIR}/src/whisperLib/lib" But I've always got the error:

 error while loading shared libraries: libwhisper.so.1: cannot open shared object file: No such file or directory

Trial 1:

set(CMAKE_INSTALL_RPATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")

Trial 2 :

list( APPEND CMAKE_INSTALL_RPATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")

Trial 3:

set(CMAKE_BUILD_RPATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")

Trial 4:

set(RPATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")
list (APPEND CMAKE_BUILD_RPATH ${RPATH})

Trial 5:

add_library(libwhisper SHARED IMPORTED)
set (RPATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")
set_target_properties(libwhisper PROPERTIES
    LINK_FLAGS "-Wl,-rpath,${RPATH}"
)

Trial 6:

find_library(libwhisper PATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")

Trial 7:

set (CMAKE_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/src/whisperLib/lib")
find_library(NAMES libwhisper)

Trial 8:

add_library(libwhisper SHARED IMPORTED)
set_target_properties(libwhisper PROPERTIES
    IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/src/whisperLib/lib"
    INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src/whisperLib/include/whisper.h" 
)

Update 3 )

I made an "experiment": I replicated what I've did in another Ubuntu 24.04 machine:

I first installed libopenblas-dev, a library needed to speed-up some calculations. But it should not impact anything else

And then installed, in the "canonical way" (not in a custom folder), the whisper.cpp library.

In CMakeLists.txt I removed everything related to libwhisper.

$ sudo apt-get install libopenblas-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libopenblas-pthread-dev libopenblas0 libopenblas0-pthread
The following NEW packages will be installed:
  libopenblas-dev libopenblas-pthread-dev libopenblas0 libopenblas0-pthread
0 upgraded, 4 newly installed, 0 to remove and 33 not upgraded.
Need to get 12.1 MB of archives.
After this operation, 107 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://it.archive.ubuntu.com/ubuntu noble/universe amd64 libopenblas0-pthread amd64 0.3.26+ds-1 [7,175 kB]
Get:2 http://it.archive.ubuntu.com/ubuntu noble/universe amd64 libopenblas0 amd64 0.3.26+ds-1 [6,168 B]
Get:3 http://it.archive.ubuntu.com/ubuntu noble/universe amd64 libopenblas-pthread-dev amd64 0.3.26+ds-1 [4,900 kB]
Get:4 http://it.archive.ubuntu.com/ubuntu noble/universe amd64 libopenblas-dev amd64 0.3.26+ds-1 [19.6 kB]
Fetched 12.1 MB in 1s (16.3 MB/s)
Selecting previously unselected package libopenblas0-pthread:amd64.
(Reading database ... 226289 files and directories currently installed.)
Preparing to unpack .../libopenblas0-pthread_0.3.26+ds-1_amd64.deb ...
Unpacking libopenblas0-pthread:amd64 (0.3.26+ds-1) ...
Selecting previously unselected package libopenblas0:amd64.
Preparing to unpack .../libopenblas0_0.3.26+ds-1_amd64.deb ...
Unpacking libopenblas0:amd64 (0.3.26+ds-1) ...
Selecting previously unselected package libopenblas-pthread-dev:amd64.
Preparing to unpack .../libopenblas-pthread-dev_0.3.26+ds-1_amd64.deb ...
Unpacking libopenblas-pthread-dev:amd64 (0.3.26+ds-1) ...
Selecting previously unselected package libopenblas-dev:amd64.
Preparing to unpack .../libopenblas-dev_0.3.26+ds-1_amd64.deb ...
Unpacking libopenblas-dev:amd64 (0.3.26+ds-1) ...
Setting up libopenblas0-pthread:amd64 (0.3.26+ds-1) ...
update-alternatives: using /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 to provide /usr/lib/x86_64-linux-gnu/libblas.so.3 (libblas.so.3-x86_64-linux-gnu) in auto mode
update-alternatives: using /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3 to provide /usr/lib/x86_64-linux-gnu/liblapack.so.3 (liblapack.so.3-x86_64-linux-gnu) in auto mode
update-alternatives: using /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblas.so.0 to provide /usr/lib/x86_64-linux-gnu/libopenblas.so.0 (libopenblas.so.0-x86_64-linux-gnu) in auto mode
Setting up libopenblas0:amd64 (0.3.26+ds-1) ...
Setting up libopenblas-pthread-dev:amd64 (0.3.26+ds-1) ...
update-alternatives: using /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so to provide /usr/lib/x86_64-linux-gnu/libblas.so (libblas.so-x86_64-linux-gnu) in auto mode
update-alternatives: using /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so to provide /usr/lib/x86_64-linux-gnu/liblapack.so (liblapack.so-x86_64-linux-gnu) in auto mode
update-alternatives: using /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblas.so to provide /usr/lib/x86_64-linux-gnu/libopenblas.so (libopenblas.so-x86_64-linux-gnu) in auto mode
Setting up libopenblas-dev:amd64 (0.3.26+ds-1) ...
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...


~/Downloads/whisper.cpp/builddir$ sudo make install
[ 19%] Built target ggml-base
[ 41%] Built target ggml-cpu
[ 46%] Built target ggml
[ 51%] Built target whisper
[ 60%] Built target common
[ 65%] Built target whisper-cli
[ 70%] Built target whisper-bench
[ 75%] Built target whisper-server
[ 80%] Built target quantize
[ 85%] Built target main
[ 90%] Built target bench
[ 95%] Built target stream
[100%] Built target command
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libwhisper.so.1.7.4
-- Installing: /usr/local/lib/libwhisper.so.1
-- Set non-toolchain portion of runtime path of "/usr/local/lib/libwhisper.so.1.7.4" to ""
-- Installing: /usr/local/lib/libwhisper.so
-- Installing: /usr/local/include/whisper.h
-- Installing: /usr/local/lib/cmake/whisper/whisper-config.cmake
-- Installing: /usr/local/lib/cmake/whisper/whisper-version.cmake
-- Installing: /usr/local/lib/pkgconfig/whisper.pc
-- Installing: /usr/local/lib/libggml-cpu.so
-- Set non-toolchain portion of runtime path of "/usr/local/lib/libggml-cpu.so" to ""
-- Installing: /usr/local/lib/libggml.so
-- Set non-toolchain portion of runtime path of "/usr/local/lib/libggml.so" to ""
-- Installing: /usr/local/include/ggml.h
-- Installing: /usr/local/include/ggml-cpu.h
-- Installing: /usr/local/include/ggml-alloc.h
-- Installing: /usr/local/include/ggml-backend.h
-- Installing: /usr/local/include/ggml-blas.h
-- Installing: /usr/local/include/ggml-cann.h
-- Installing: /usr/local/include/ggml-cuda.h
-- Installing: /usr/local/include/ggml-kompute.h
-- Installing: /usr/local/include/ggml-opt.h
-- Installing: /usr/local/include/ggml-metal.h
-- Installing: /usr/local/include/ggml-rpc.h
-- Installing: /usr/local/include/ggml-sycl.h
-- Installing: /usr/local/include/ggml-vulkan.h
-- Installing: /usr/local/include/gguf.h
-- Installing: /usr/local/lib/libggml-base.so
-- Installing: /usr/local/bin/whisper-cli
-- Set non-toolchain portion of runtime path of "/usr/local/bin/whisper-cli" to ""
-- Installing: /usr/local/bin/whisper-bench
-- Set non-toolchain portion of runtime path of "/usr/local/bin/whisper-bench" to ""
-- Installing: /usr/local/bin/whisper-server
-- Set non-toolchain portion of runtime path of "/usr/local/bin/whisper-server" to ""

Two things:

  • In this way I do not get the error libwhisper.so.1 not found and it works fine.

  • The output of ldd ./MyPrj/builddir/MyPrj does not contain any references to libwhisper

What these two things mean?

What am I doing wrong and/or missing? How to make it work?

cmake version 3.28.3 OS: Ubuntu 24.04

How make the library visible?


Solution

  • When compiling the whisper.cpp project, it will generate the .so and .so.1 files in the whisper.cpp/build/src/ directory. So, there are two solutions:

    • Move the .so and .so.1 files to the directory where the whisper binary is located. This works, but you may prefer to have everything packed into a single binary, so solution 2 might be more interesting for you.

    • Compile the program with the libraries statically linked: To do this, you need to modify the CMakeLists.txt file. Look for the following section:

    This enables shared linking, look at the code inside the 'else'

    if (MINGW)
        set(BUILD_SHARED_LIBS_DEFAULT OFF)
    else()
        set(BUILD_SHARED_LIBS_DEFAULT ON) # change this
    endif()
    

    To disable it and use static linking, change it to:

    set(BUILD_SHARED_LIBS_DEFAULT OFF)

    This change will make CMake build the libraries statically, so you won't need the .so files anymore.