Building OpenCV 3.3 requires a newer GCC

On TK1’s Ubuntu I’m trying to compile OpenCV and it fails. The first error from CMakeFiles/CMakeError.log is:

Compilation failed:
    source file: '/home/nvidia/work/opencv/cmake/checks/cxx11.cpp'
    check option: ''
===== BUILD LOG =====
Change Dir: /home/nvidia/work/opencv/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_cb2c5/fast"
/usr/bin/make -f CMakeFiles/cmTC_cb2c5.dir/build.make CMakeFiles/cmTC_cb2c5.dir/build
make[1]: Entering directory '/home/nvidia/work/opencv/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_cb2c5.dir/cxx11.cpp.o
/usr/bin/c++     -o CMakeFiles/cmTC_cb2c5.dir/cxx11.cpp.o -c /home/nvidia/work/opencv/cmake/checks/cxx11.cpp
/home/nvidia/work/opencv/cmake/checks/cxx11.cpp:4:2: error: #error "C++11 is not supported"
 #error "C++11 is not supported"
  ^
/home/nvidia/work/opencv/cmake/checks/cxx11.cpp: In function 'int main()':
/home/nvidia/work/opencv/cmake/checks/cxx11.cpp:11:10: error: 'res' does not name a type
     auto res = test();
          ^
/home/nvidia/work/opencv/cmake/checks/cxx11.cpp:12:12: error: 'res' was not declared in this scope
     return res;
            ^
CMakeFiles/cmTC_cb2c5.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_cb2c5.dir/cxx11.cpp.o' failed
make[1]: *** [CMakeFiles/cmTC_cb2c5.dir/cxx11.cpp.o] Error 1
make[1]: Leaving directory '/home/nvidia/work/opencv/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_cb2c5/fast' failed
make: *** [cmTC_cb2c5/fast] Error 2

===== END =====

I understand the c++ compiler is too old:

$ c++ --version
c++ (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

I looked into how to install a newer Linaro gcc and I found on the Linaro website:
https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/
I’m looking there at gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu.tar.xz and I’m wondering if there is an easier way to install a newer gcc on the TK1’s Ubuntu.

Try “-std=c++11”. C++11 isn’t the default behavior, but should be available.

mkdir opencv_release &&
cd release &&

cmake …/opencv-3.3.0
-DCMAKE_INSTALL_PREFIX=/usr
-DCMAKE_BUILD_TYPE=Release
-DENABLE_CXX11=ON
-DBUILD_PERF_TESTS=OFF
-DWITH_XINE=ON
-DBUILD_TESTS=OFF
-DENABLE_PRECOMPILED_HEADERS=OFF
-DCMAKE_SKIP_RPATH=ON
-DBUILD_WITH_DEBUG_INFO=OFF
.
.
.
.

I don’t know if “-DENABLE_CXX11=ON” is the same thing or not. Does the compile show an actual “-std=c++11”?

Hey Man,
I had the same error while building it openCV for GPU. I solved the error by using the accepted solution provided https://stackoverflow.com/questions/45521747/compiling-opencv-3-3-c11-is-not-supported