Building OpenCV from source: gcc and CUDA versions

CUDA lags with support for newer versions of gcc, e.g. CUDA 11 works only with gcc-9 and older. OpenCV, on the other hand can be built with newer versions of gcc. Is it necessary to restrict the gcc version when buildin OpenCV with CUDA functionality enabled?

Yes. You have to set CUDA_HOST_COMPILER flag to /usr/bin/gcc-8 in cmake in order to correctly build OpenCV with CUDA support (otherwise nvcc will exit with an error while building the CUDA modules).

2 Likes

Thank you. CUDA_HOST_COMPILER is what I was looking for. Setting it to /usr/bin/gcc-9 will work with CUDA version 11.x.