CMAKE选项包含目录

时间:2013-03-04 19:12:18

标签: c++ opencv cmake cross-compiling

我正在尝试在基于ARM-linux的系统上编译OPENCV。为此,我使用以下选项

创建了一个工具链cmake文件
SET (CMAKE_SYSTEM_NAME Linux)
SET (CMAKE_SYSTEM_VERSION 1)
SET (CMAKE_SYSTEM_PROCESSOR arm)

SET (CMAKE_C_COMPILER "/usr/local/arm/4.3.1-eabi-armv6/usr/bin/arm-linux-gcc")
SET (CMAKE_CXX_COMPILER "/usr/local/arm/4.3.1-eabi-armv6/usr/bin/arm-linux-g++")

SET (CMAKE_FIND_ROOT_PATH "/usr/local/arm/4.3.1-eabi-armv6/")
SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

SET (LIBRARY_OUTPUT_PATH "/home/xxx/OpenCV-2.4.3/lib")
SET (OPENCV_CONFIG_FILE_INCLUDE_DIR "/home/xxx/OpenCV-2.4.3")
SET (OPENCV_WARNINGS_ARE_ERRORS OFF)

运行cmake命令并生成命令后,我收到以下错误:

In file included from /usr/local/arm/4.3.1-eabi-armv6/usr/bin-ccache/../lib/gcc/arm-samsung-linux-gnueabi/4.3.1/../../../../arm-samsung-linux-gnueabi/include/c++/4.3.1/bits/postypes.h:47,
             from /usr/local/arm/4.3.1-eabi-armv6/usr/bin-ccache/../lib/gcc/arm-samsung-linux-gnueabi/4.3.1/../../../../arm-samsung-linux-gnueabi/include/c++/4.3.1/iosfwd:47,
             from /usr/local/arm/4.3.1-eabi-armv6/usr/bin-ccache/../lib/gcc/arm-samsung-linux-gnueabi/4.3.1/../../../../arm-samsung-linux-gnueabi/include/c++/4.3.1/ios:44,
             from /usr/local/arm/4.3.1-eabi-armv6/usr/bin-ccache/../lib/gcc/arm-samsung-linux-gnueabi/4.3.1/../../../../arm-samsung-linux-gnueabi/include/c++/4.3.1/ostream:45,
             from /usr/local/arm/4.3.1-eabi-armv6/usr/bin-ccache/../lib/gcc/arm-samsung-linux-gnueabi/4.3.1/../../../../arm-samsung-linux-gnueabi/include/c++/4.3.1/iostream:45,
             from /home/zwang/OpenCV-2.4.3/3rdparty/openexr/Half/half.h:88,
             from /home/zwang/OpenCV-2.4.3/3rdparty/openexr/Half/half.cpp:48:
/usr/local/arm/4.3.1-eabi-armv6/usr/bin-ccache/../lib/gcc/arm-samsung-linux-gnueabi/4.3.1/../../../../arm-samsung-linux-gnueabi/include/c++/4.3.1/cwchar:52:24: error: wchar.h: No such file or directory

总结:编译器无法找到wchar.h,stdio.h,wctype.h,ctype.h。这些头文件存在于/usr/local/arm/4.3.1-eabi-armv6/usr/include中。我想我需要使用cmake选项包含这个文件夹。我怎样才能做到这一点?

4 个答案:

答案 0 :(得分:2)

您可以通过include_directories命令执行此操作:

include_directories(SYSTEM /usr/local/arm/4.3.1-eabi-armv6/usr/include)

更强大的解决方案是在此路径中搜索标头,如果找到包含目录,或者失败。除了将本地路径硬编码到CMakeLists.txt中之外,还有一个好处是,它在CMake运行时失败,而不是在以后的构建时失败。最好使用find_path完成此操作。

例如,你可以这样做:

find_path(WcharPath wchar.h PATHS /usr/local/arm/4.3.1-eabi-armv6/usr/include)
if(WcharPath)
  include_directories(SYSTEM ${WcharPath})
else()
  message(FATAL_ERROR "Failed to find wchar.h")
endif()

答案 1 :(得分:0)

您可以设置CMAKE_SYSROOT来解决此问题。看起来你应该把它设置为

/usr/local/arm/4.3.1-eabi-armv6/

在这种情况下。

http://www.cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling

答案 2 :(得分:-1)

您可以将CMAKE_INCLUDE_PATH设置为环境变量,CMAKE文档中提供了有关格式的说明:

http://www.cmake.org/Wiki/CMake_Useful_Variables

答案 3 :(得分:-1)

您应该将它放在工具链文件中,因为标题位置取决于特定的工具链部署:

set(CMAKE_CXX_FLAGS "-isystem /usr/local/arm/4.3.1-eabi-armv6/usr/include")
set(CMAKE_C_FLAGS "-isystem /usr/local/arm/4.3.1-eabi-armv6/usr/include")