CMAKE option to include a directory

2019-07-29 10:42发布

am trying to compile OPENCV on ARM-linux based system. For this purpose I created a toolchain cmake file with the following options

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)

After running the cmake command and make command I am getting the following error:

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

Summarizing : the compiler is not able to find wchar.h, stdio.h, wctype.h, ctype.h. These headers are present in /usr/local/arm/4.3.1-eabi-armv6/usr/include . I guess I need to include this folder using cmake options. How can I do that?

4条回答
虎瘦雄心在
2楼-- · 2019-07-29 11:06

You can set CMAKE_INCLUDE_PATH as an environmental variable, description on the format is available in the CMAKE documentation :

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

查看更多
Rolldiameter
3楼-- · 2019-07-29 11:12

You should put this in your toolchain file since the header locations depend on that specific toolchain deployment:

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")
查看更多
在下西门庆
4楼-- · 2019-07-29 11:15

You can set CMAKE_SYSROOT to solve this. It looks like you should set it to

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

in this case.

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

查看更多
干净又极端
5楼-- · 2019-07-29 11:25

You can do this via the include_directories command:

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

A more robust solution would be to search for a header in this path, and if found include the directory, or else fail. As well as being more robust than hard-coding a local path into your CMakeLists.txt, another benefit is that it fails at CMake run time, rather than at build time later on. This is best done using find_path.

For example, you could do:

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()
查看更多
登录 后发表回答