【发布时间】:2021-04-23 21:53:16
【问题描述】:
目前我正在尝试为我的 uni 项目生成一些频谱图。我正在尝试构建一个静态库,所有魔法都可以在其中发挥作用,只需从 main() 函数调用它。
这是我的 cmake 文件:
set(CMAKE_CXX_STANDARD 17)
project(demo)
find_package(SndFile REQUIRED)
add_subdirectory(spectogram)
add_executable(demo main.cpp)
target_link_libraries (demo LINK_PUBLIC Spectrogram)
target_link_libraries(demo PRIVATE SndFile::sndfile)
我已经通过 homebrew 安装了 libsndfile,但是 find_package() 拒绝定位 lib 并抛出此错误:
CMake Error at CMakeLists.txt:6 (find_package):
By not providing "FindSndFile.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SndFile", but
CMake did not find one.
Could not find a package configuration file provided by "SndFile" with any
of the following names:
SndFileConfig.cmake
sndfile-config.cmake
Add the installation prefix of "SndFile" to CMAKE_PREFIX_PATH or set
"SndFile_DIR" to a directory containing one of the above files. If
"SndFile" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
我做了一些研究,发现 libsndfile 内部没有任何 .cmake 配置,就像其他库一样,我可以轻松链接(如 OpenCV 或 spdlog)。我非常感谢任何帮助解决这个恐怖问题。
【问题讨论】:
-
看起来sndfile project 为
sndfile.pc提供了一个文件sndfile.pc,因此您可以为该项目使用CMake 模块PkgConfig。请参阅that question 了解如何使用该 CMake 模块。 -
谢谢,@Tsyvarev,看起来 pkg-config 确实有帮助。它找到了包,但不知何故找不到 sndfile.hh 文件,所以我检查了 LIBSNDFILE_LIBRARIES 和 LIBSNDFILE_INCLUDE_DIRS 变量,它们是空的。我找到了FindLibSndFile.cmake 并将其包含在我的 cmake 文件中并且它有效!
标签: c++ cmake libsndfile