2

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?

Ravi
  • 53
  • 1
  • 7

3 Answers3

4

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()
Fraser
  • 74,704
  • 20
  • 238
  • 215
  • do I need to include this in CMakeLists.txt? – Ravi Mar 04 '13 at 19:52
  • @user1443452 - Yes. See my edit for a slightly more robust solution. – Fraser Mar 04 '13 at 20:00
  • Thanks a lot Fraser... I am getting the same error even after including your tweak .. the files compiled with gcc are working fine. But the files which are getting compiled with g++ produces this error. – Ravi Mar 04 '13 at 22:18
  • @user1443452 I'm not familiar with ARM. As a guess, have you tried adding `CXX` to the list of languages in your `project` command? See [the docs](http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:project) – Fraser Mar 04 '13 at 22:28
  • @user1443452 - I just noticed you never actually mentioned that you were cross-compiling. I assume you *are* cross-compiling? Otherwise you shouldn't need a toolchain file. – Fraser Mar 04 '13 at 22:41
  • Yes I am cross-compiling. I am sorry for the confusion. Can you please elaborate on adding CXX thing. I am new to CMAKE and cross-compiling. sorry for the weird questions – Ravi Mar 05 '13 at 13:46
  • I went deep in to the code. cwchar includes wchar.h using directive #include_next. I found all the errors the compiler produces is due to this preprocessor directive. – Ravi Mar 05 '13 at 15:26
  • Sorry Ravi - I'm running out of ideas. [This question](http://stackoverflow.com/q/10261382/424459) discusses the use of `#include_next`, but it appears to boil down to the same issue. Could you post the output of `make VERBOSE=1` to see what the actual applied make command is? It'll show what search paths are being included. – Fraser Mar 05 '13 at 22:51
  • /usr/local/arm/4.3.1-eabi-armv6/usr/bin/arm-linux-gcc -DHAVE_CVCONFIG_H -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fPIC -Wno-cast-align -Wno-shadow -Wno-unused -O3 -DNDEBUG -DNDEBUG -I/home/zwang/OpenCV-2.4.3/3rdparty/libjpeg -I/home/zwang/OpenCV-2.4.3/build_4 -o CMakeFiles/libjpeg.dir/jerror.c.o -c /home/zwang/OpenCV-2.4.3/3rdparty/libjpeg/jerror.c – Ravi Mar 06 '13 at 17:10
  • /usr/local/arm/4.3.1-eabi-armv6/usr/bin/arm-linux-g++ -DNDEBUG -I/home/zwang/OpenCV-2.4.3/3rdparty/openexr/IlmImf -I/home/zwang/OpenCV-2.4.3/3rdparty/openexr/Imath -I/home/zwang/OpenCV-2.4.3/3rdparty/openexr/IlmThread -I/home/zwang/OpenCV-2.4.3/3rdparty/openexr/Iex -I/home/zwang/OpenCV-2.4.3/3rdparty/openexr/Half -I/home/zwang/OpenCV-2.4.3/build_4/3rdparty/openexr -I/home/zwang/OpenCV-2.4.3/build_4 -isystem /usr/local/arm/4.3.1-eabi-armv6/usr/include -o CMakeFiles/IlmImf.dir/Half/half.cpp.o -c /home/zwang/OpenCV-2.4.3/3rdparty/openexr/Half/half.cpp – Ravi Mar 06 '13 at 17:12
  • First one for gcc and next one for g++ – Ravi Mar 06 '13 at 17:12
  • Nope - I'm afraid I'm stuck :-( I can see `-isystem /usr/local/arm/4.3.1-eabi-armv6/usr/include` in the g++ command which should allow headers in there to be found. It seems suspicious that there are so many flags passed in the gcc command, and absolutely none in the g++ one (except `-DNDEBUG` and the search paths `-I`). – Fraser Mar 06 '13 at 22:47
  • I am sorry Fraser.. for g++ command I removed the common flags and posted. the g++ has same flags as gcc. I repeat, The compiler is not able to find wchar.h, stdio.h, wctype.h, ctype.h. These headers are present in two locations 1) /usr/local/arm/4.3.1-eabi-armv6/usr/include and 2) /usr/local/arm/4.3.1-eabi-armv6/usr/arm-samsung-linux-gnueabi/include/c++/4.3.1/tr1. As the code is using include_next, it's skipping the first directory and searching for wchar.h in other directories. Simply saying, I am still finding difficulties in including 2nd directory using cmake – Ravi Mar 07 '13 at 14:15
  • @Ravi - Ah, that explains the flags, thanks! In my answer, I showed how to include the first directory. Try substituting `/usr/local/arm/4.3.1-eabi-armv6/usr/include` with `/usr/local/arm/4.3.1-eabi-armv6/usr/arm-samsung-linux-gnueabi/include/c++/4.3.1/tr1` in the `find_path` command. The file which needs this path is in the parent of the `tr1` folder. If this works (or even if it doesn't), could this be down to missing [`-std=c++0x` or `-std=c++11`](http://gcc.gnu.org/projects/cxx0x.html) from the compile flags? – Fraser Mar 07 '13 at 19:17
1

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

steveire
  • 10,694
  • 1
  • 37
  • 48
-1

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

ahjmorton
  • 965
  • 1
  • 5
  • 18
  • used this option .. SET (CMAKE_INCLUDE_PATH "/usr/local/arm/4.3.1-eabi-armv6/usr/include") .. but same error – Ravi Mar 04 '13 at 19:44
  • 1
    This only brings the directory into scope for CMake's own use - it's useful if you want to find a file/lib/etc. and wish CMake to always look in the given path. Check out the docs for e.g. [`find_file`](http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_file), especially point 1. – Fraser Mar 04 '13 at 19:49