Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake cannot find libsndfile

Cmake seems not to find the lib libsndfile. However, it installed on my machine.

find_library(sndfile REQUIRED)

And installed :

yum list installed | grep libsnd
libsndfile.x86_64                       1.0.25-11.el7            @base          
libsndfile-devel.x86_64                 1.0.25-11.el7            @base  

The error :

 CMake Error at CMakeLists.txt:65 (find_library):
   Could not find sndfile using the following names:

CMakeLists.txt :

cmake_minimum_required(VERSION 3.19)
project(untitled1)

set(CMAKE_CXX_STANDARD 11)

find_library(sndfile REQUIRED)

add_executable(untitled1 main.cpp)

Main.cpp

#include <iostream>

int main() {
  std::cout << "Hello, World!" << std::endl;
  return 0;
}
like image 992
mm98 Avatar asked Aug 06 '26 12:08

mm98


1 Answers

It doesn't mean much if it is installed on your machine or not. CMake won't search all your computer for the library. The best thing you can do is to add the location of the installed library to your PATH environment variable.

Here's what CMake documentation says about find_library() HINTS and PATHS arguments:

HINTS, PATHS

Specify directories to search in addition to the default locations. The ENV var sub-option reads paths from a system environment variable.

CMake also provides another solution: set CMAKE_PREFIX_PATH You can find more details about it here.

like image 94
Attis Avatar answered Aug 08 '26 01:08

Attis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!