【问题标题】:CMake works on Mac, but not Linux?CMake 适用于 Mac,但不适用于 Linux?
【发布时间】:2014-05-18 02:12:26
【问题描述】:

我有以下CMakeLists.txt

cmake_minimum_required (VERSION 2.8.7)
project (Test)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

find_package(CURL REQUIRED)
find_package(PortAudio REQUIRED)
find_package(LibSndFile REQUIRED)

include_directories(src/audio src/web)
set(LIBS ${LIBS} ${LIBSNDFILE_LIBRARY} ${PORTAUDIO_LIBRARIES} ${CURL_LIBRARIES})
file(GLOB_RECURSE sources ${PROJECT_SOURCE_DIR}/src/*.c)

add_executable(Test ${sources})
target_link_libraries(Test ${LIBS})

这是我的文件夹结构:

Test/
├── .gitignore
├── README
├── CMakeLists.txt
├── src/
│   ├── audio/
│   │   └── ...
│   ├── web/
│   │   └── ...
│   └── ...
├── build/
└── cmake/
    ├── FindLibSndFile.cmake
    └── FindPortaudio.cmake

当我在 Mac 上编译我的程序时,我进入build/ 目录并运行程序生成的cmake ..

-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found CURL: /usr/lib/libcurl.dylib (found version "7.30.0") 
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.28") 
-- checking for module 'portaudio-2.0'
--   found portaudio-2.0, version 19
-- Found LibSndFile: /usr/local/lib/libsndfile.dylib
-- Configuring done
-- Generating done
-- Build files have been written to: Development/Test/build

一切都运行良好,花花公子。但是当我将源代码复制到我的 Raspberry Pi 并重复上述步骤时,它会向我吐出这个:

-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found CURL: /usr/lib/arm-linux-gnueabihf/libcurl.so (found version "7.26.0") 
CMake Error at CMakeLists.txt:7 (find_package):
  By not providing "FindPortAudio.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "PortAudio", but CMake did not find one.

  Could not find a package configuration file provided by "PortAudio" with
  any of the following names:

    PortAudioConfig.cmake
    portaudio-config.cmake

  Add the installation prefix of "PortAudio" to CMAKE_PREFIX_PATH or set
  "PortAudio_DIR" to a directory containing one of the above files.  If
  "PortAudio" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!

我不太清楚为什么它不起作用。有什么建议吗?

【问题讨论】:

    标签: c linux compilation cmake cross-platform


    【解决方案1】:

    Mac 不区分大小写,而其他操作系统通常区分大小写。要解决这个问题,要么更改文件名FindPortaudio.cmake --> FindPortAudio.cmake(注意音频中的大写A)。或在CMakeLists.txt 文件中,将音频中的A 更改为小写字符。即,改变

    find_package(PortAudio REQUIRED)
    

    find_package(Portaudio REQUIRED)
    

    【讨论】:

    • 我认为这可能与.cmake 文件的路径有关,字母的大小写问题让我感到惊讶。不过它确实有效,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    相关资源
    最近更新 更多