2

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;
}
mm98
  • 409
  • 1
  • 6
  • 18
  • 1
    You added the CMakeLists.txt but did not post the next line of the error message. What does it say after ***Could not find sndfile using the following names:*** – drescherjm Apr 30 '21 at 15:35
  • 3
    You forgot to specify **names** for you library in `find_library` call. The first parameter for [find_library](https://cmake.org/cmake/help/latest/command/find_library.html) is a **variable** name, not a *library* name. – Tsyvarev Apr 30 '21 at 15:42
  • 1
    @Tsyvarev I see now I understand the error message. I expect it's looking for a library named `libREQUIRED` – drescherjm Apr 30 '21 at 15:58
  • I would also ensure cmake has the correct values for `CMAKE_STATIC_LIBRARY_SUFFIX`, The suffix `.x86_64` seem unusual, linux distro usually have the `.a` extension – Guillaume Racicot Apr 30 '21 at 16:01
  • The yum is just the list of distro packages not the library name. – drescherjm Apr 30 '21 at 16:02
  • @drescherjm Oh! Got it, thanks. – Guillaume Racicot Apr 30 '21 at 16:02

1 Answers1

2

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.

Attis
  • 573
  • 1
  • 7
  • 19
  • 1
    My call of find_library was wrong. If I defined : find_library(sndfile libsndfile), it works. Thanks – mm98 May 03 '21 at 07:11