I have many workarounds, and finally I came up with a solution for building OpenCV 3.2 with Cuda 8 in Debian 9. There are many unanswered whys with this solution, but it really works:
1 - you need versions of the gcc compiler from 5.1 to 5.x.
2 - you must install equivalent compiler versions for g ++ (you do not need to remove new versions of the compiler)
3. OpenCV itself must be compiled using gcc 5.x, so you must select your gcc and g ++ compiler manually in CMAKE
4 - a separate compilation option should be disconnected from CMAKE thanks to @InfinityChaos for this sentence
5 - the pre-compiler option must be disconnected from CMAKE (very important)
6 - you can enable the Qt, OpenGL and OpenCl options, no problems
7 - you do not need to check the TBB option.
source share