CMake:/ usr / include不习惯查找fftw3.h

时间:2018-02-18 22:41:44

标签: c++ c cmake cross-compiling fftw

我正在开发一个个人项目来与CMake交叉编译Raspberry Pi。这是我第一次用它建立一个项目。

我编译的文件之一包括fftw3.h标题。此文件存在于/usr/include文件夹中,如以下输出所示:

$ ls /usr/include/fftw3*
/usr/include/fftw3.f
/usr/include/fftw3.f03
/usr/include/fftw3.h 
/usr/include/fftw3l.f03
/usr/include/fftw3q.f03

cmake已使用find_path(FFTW_FOLDER NAMES fftw3.h)成功找到该文件,即使cmake默认查看此路径,我也会在使用target_include_directories(${LIB_NAME} PUBLIC /usr/include)构建目标时明确添加该文件。

然而,当编译时,我有经典的错误消息,告诉我找不到fftw3.h

如果我复制文件并将其放在我的主文件夹中并将我的主文件夹添加到包含列表中,则没有问题,编译工作正常。

有什么想法吗?

谢谢, 达明

编辑1回答@Pablo和@hikerjobs

这就是我的编译行的样子:

/home/littlemonster/projects/rpi-workspace/rpi-tools/arm-bcm2708/gcc-
linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++   
-Dmatrix_hal_EXPORTS -I/home/littlemonster/projects/rpi-
workspace/lib/matrix-hal/matrix-creator-hal  -fPIC   -Wall -Werror -
Wextra -Wdouble-promotion -std=gnu++11 -o CMakeFiles/matrix-
hal.dir/matrix-creator-hal/cpp/driver/cross_correlation.cpp.o -c 
/home/littlemonster/projects/rpi-workspace/lib/matrix-hal/matrix-
creator-hal/cpp/driver/cross_correlation.cpp

In file included from /home/littlemonster/projects/rpi-
workspace/lib/matrix-hal/matrix-creator-
hal/cpp/driver/cross_correlation.cpp:18:0:
/home/littlemonster/projects/rpi-workspace/lib/matrix-hal/matrix-
creator-hal/cpp/driver/cross_correlation.h:21:19: fatal error: 
fftw3.h: No such file or directory
#include <fftw3.h>
               ^
compilation terminated.

因为我正在交叉编译并且Raspberry Pi上存在库,所以我没有链接库。

编辑2回答@Bartłomiej

以下行位于我的rpi-toolchain.cmake文件中,该文件在使用以下内容调用cmake时使用:-DCMAKE_TOOLCHAIN_FILE=rpi-toolchain.cmake。当我尝试通过设置CMAKE_SYSROOT来指定sysroot时,编译器甚至无法编译测试文件。

# Define our host system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)

SET(rpi-tools-dir ${CMAKE_SOURCE_DIR}/rpi-tools)

# Define the C cross compiler location
SET(CMAKE_C_COMPILER  ${rpi-tools-dir}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc)

# Define the CXX cross compiler location
SET(CMAKE_CXX_COMPILER  ${rpi-tools-dir}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++)

# Define the sysroot path for the RaspberryPi distribution in our tools folder
SET(CMAKE_FIND_ROOT_PATH ${rpi-tools-dir}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/sysroot/)

# Only use binaries from the host and not from the toolchain sysroot
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# Search for libraries only in the target sysroot
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
# Search for the headers in the target and host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)

0 个答案:

没有答案