Compiling OpenCV with GCC7 fails with fatal_error at stdlib include_next
Hello,
we're currently developing ROS support for our modules. Therefore we need to compile ROS Kinetic packages with the gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf toolchain.
I get the following error:
[ 63%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window.cpp.o
In file included from /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1/ext/string_conversions.h:41:0,
from /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1/bits/basic_string.h:6349,
from /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1/string:52,
from /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1/stdexcept:39,
from /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1/array:39,
from /ros_files_comm_cv/src/opencv3/modules/core/include/opencv2/core/cvdef.h:438,
from /ros_files_comm_cv/src/opencv3/modules/core/include/opencv2/core.hpp:52,
from /ros_files_comm_cv/src/opencv3/modules/highgui/include/opencv2/highgui.hpp:46,
from /ros_files_comm_cv/src/opencv3/modules/highgui/src/precomp.hpp:45,
from /ros_files_comm_cv/src/opencv3/modules/highgui/src/window.cpp:42:
/opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>**
^~~~~~~~~~
compilation terminated.
modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:83: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/window.cpp.o' failed
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window.cpp.o] Error 1
CMakeFiles/Makefile2:3404: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
My command looks like this:
sudo ./src/catkin/bin/catkin_make_isolated -DCMAKE_TOOLCHAIN_FILE=/toolchains/rostoolchain.cmake --install --install-space /opt/ros-arm -DCMAKE_BUILD_TYPE=Release -DCATKIN_ENABLE_TESTING=false -DWITH_1394=OFF -DWITH_CUDA=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_videoio=OFF -DENABLE_PRECOMPILED_HEADERS=OFF
My rostoolchain file looks like this:
#File: rostoolchain.cmake
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_LIBRARY_PATH /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/)
set(CMAKE_C_COMPILER /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc)
set(CMAKE_INCLUDE_PATH /opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/)
set(CMAKE_C_FLAGS -I/opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include)
#Have to set this one to BOTH, to allow CMake to find rospack
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
I already found out that there was a problem when upgrading from GCC5 to GCC6. The problem was solved by adding -DENABLE_PRECOMPILED_HEADERS=OFF to the command. But this only shifts my error from 25% building to 62% building. When I remove the '_next' at
/opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/7.2.1**/cstdlib:75:15
#include_next <stdlib.h>
everything works fine. But I need a solution that doesn't require a change in the toolchain. Maybe somebody is fighting with the same issue? Does anybody know another solution for my problem?
Please note: OpenCV is a stand-alone project. It's not (directly) related to ROS. ROS uses OpenCV, but you may want to report this over at the OpenCV issue tracker(s) / support fora.
Also: is this really an OpenCV problem? Not having
stdlib.h
seems like a strange thing for C++ compiler.Did you make sure you provide
stdlib.h
?#include_next
specifies that you want to use your own version, so you have to provide this custom version! Iffind ./src -name "stdlib.h"
yelds zero results then you are missing a file in your project.Yes I guess that this OpenCV package isn't customized for GCC 7 yet. I do not provide my own custom version of stdlib.h because I only want to build the OpenCV package. I can actually compile almost every package except for this one. (I download the packages with rosinstall_generator and wstool).
A quick google shows that this is a known problem with OpenCV (ie: upstream), see OpenCV build fails - stdlib.h missing for instance. Supposedly fixed, but could be that the version you download with
rosinstall_generator
misses the fix.In any case: if the version
rosinstall_generator
gives you includes the fix, then I would suggest to report this upstream.