Required g++/gcc version for compiling from source?

I am having difficulty compiling OpenCV 4.5.5 (on CentOS 7). I have tried GCC 4, GCC 9, and GCC 10. All give different errors, which upon googling seem to do with the particular version of GCC.

So is there a required or recommended GCC version? Or perhaps the GCC version needs to match the version CUDA was compiled with? Or match the system GCC?

I won’t list all my compilation errors, but here’s the latest one with GCC 4.9.2:

cd /usr/local/src/opencv_build/opencv/build/modules/gapi && /usr/local/bin/c++  -DCVAPI_EXPORTS -DOPENCV_WITH_ITT=1 -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/local/src/opencv_build/opencv/build/3rdparty/ippicv/ippicv_lnx/icv/include -I/usr/local/src/opencv_build/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include -I/usr/local/src/opencv_build/opencv/build -I/usr/local/src/opencv_build/opencv/modules/gapi/include -I/usr/local/src/opencv_build/opencv/build/modules/gapi -I/usr/local/src/opencv_build/opencv_contrib/modules/cudev/include -I/usr/local/src/opencv_build/opencv/modules/core/include -I/usr/local/src/opencv_build/opencv/modules/flann/include -I/usr/local/src/opencv_build/opencv/modules/imgproc/include -I/usr/local/src/opencv_build/opencv/modules/dnn/include -I/usr/local/src/opencv_build/opencv/modules/features2d/include -I/usr/local/src/opencv_build/opencv/modules/calib3d/include -I/usr/local/src/opencv_build/opencv/modules/video/include -I/usr/local/src/opencv_build/opencv/modules/gapi/src -I/usr/local/src/opencv_build/opencv/3rdparty/ittnotify/include -I/usr/local/src/opencv_build/opencv/modules/ts/include -I/usr/local/src/opencv_build/opencv/modules/imgcodecs/include -I/usr/local/src/opencv_build/opencv/modules/videoio/include -I/usr/local/src/opencv_build/opencv/modules/highgui/include -I/usr/local/src/opencv_build/opencv/build/3rdparty/ade/ade-0.1.1f/sources/ade/include  -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O2 -g -DNDEBUG -fPIC   -std=c++11 -o CMakeFiles/opencv_gapi.dir/src/backends/ie/giebackend.cpp.o -c /usr/local/src/opencv_build/opencv/modules/gapi/src/backends/ie/giebackend.cpp
/usr/local/src/opencv_build/opencv/modules/gapi/include/opencv2/gapi/infer/ie.hpp:392:20: error: converting to ‘std::unordered_map<std::basic_string<char>, std::pair<cv::Mat, cv::gapi::ie::TraitAs> >’ from initializer list would use explicit constructor ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const hasher&, const key_equal&, const allocator_type&) [with _Key = std::basic_string<char>; _Tp = std::pair<cv::Mat, cv::gapi::ie::TraitAs>; _Hash = std::hash<std::basic_string<char> >; _Pred = std::equal_to<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::pair<cv::Mat, cv::gapi::ie::TraitAs> > >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type = long unsigned int; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher = std::hash<std::basic_string<char> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal = std::equal_to<std::basic_string<char> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type = std::allocator<std::pair<const std::basic_string<char>, std::pair<cv::Mat, cv::gapi::ie::TraitAs> > >]’
           m_tag(tag) {
                    ^
/usr/local/src/opencv_build/opencv/modules/gapi/include/opencv2/gapi/infer/ie.hpp:392:20: error: converting to ‘std::unordered_set<std::basic_string<char> >’ from initializer list would use explicit constructor ‘std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(std::unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type, const hasher&, const key_equal&, const allocator_type&) [with _Value = std::basic_string<char>; _Hash = std::hash<std::basic_string<char> >; _Pred = std::equal_to<std::basic_string<char> >; _Alloc = std::allocator<std::basic_string<char> >; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type = long unsigned int; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::hasher = std::hash<std::basic_string<char> >; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::key_equal = std::equal_to<std::basic_string<char> >; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::allocator_type = std::allocator<std::basic_string<char> >]’
make[2]: *** [modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ie/giebackend.cpp.o] Error 1
make[2]: Leaving directory `/usr/local/src/opencv_build/opencv/build'
make[1]: *** [modules/gapi/CMakeFiles/opencv_gapi.dir/all] Error 2
make[1]: Leaving directory `/usr/local/src/opencv_build/opencv/build'
make: *** [all] Error 2