Compiling Opencv Error

When I compile opencv , I get the following errors, what could be the reason?

Ubuntu 22.04.2 LTS
Opencv 4.6.0
NVIDIA-SMI 535.54.03 Driver Version: 535.54.03 CUDA Version: 12.2

– NVIDIA GPU arch: 75
– NVIDIA PTX archs:

– cuDNN: YES (ver 8.9.2)

make -j16:

[  6%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfEnvmapAttribute.cpp.o
/root/opencv/modules/core/include/opencv2/core/cuda/common.hpp(99): error: identifier "textureReference" is undefined
          template<class T> inline void bindTexture(const textureReference* tex, const PtrStepSz<T>& img)

3 errors detected in the compilation of "/root/opencv/modules/core/src/cuda/".
CMake Error at (message):
  Error generating file

make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/build.make:77: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/] Error 1
make[2]: *** Waiting for unfinished jobs....
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dsp/yuv_mips_dsp_r2.c.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dsp/yuv_neon.c.o
[  6%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfFloatAttribute.cpp.o
[  6%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfFastHuf.cpp.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dsp/yuv_sse2.c.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dsp/yuv_sse41.c.o
[  6%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfFloatVectorAttribute.cpp.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/alpha_enc.c.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/analysis_enc.c.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/backward_references_cost_enc.c.o
[  6%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/backward_references_enc.c.o
[  6%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfFrameBuffer.cpp.o
[  7%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfFramesPerSecond.cpp.o
[  7%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfGenericInputFile.cpp.o
[  7%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/config_enc.c.o
[  7%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/cost_enc.c.o
[  7%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/
[  7%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/filter_enc.c.o
/root/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(61): error: texture is not a template
          typedef texture<T, 0x02, cudaReadModeElementType> TexRef;

/root/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(83): error: identifier "cudaUnbindTexture" is undefined

[  7%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/frame_enc.c.o
[  7%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/histogram_enc.c.o
[  7%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/
[  7%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/io/
2 errors detected in the compilation of "/root/opencv/modules/core/src/cuda/".
[  7%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/enc/iterator_enc.c.o
CMake Error at (message):
  Error generating file

make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/build.make:84: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/] Error 1
make[1]: *** [CMakeFiles/Makefile2:5277: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

maybe you can get a clearer error output, if you remove the -j8 from your make cmdline, then we could see, which cpp file really triggers this (unlikely it is from the exr code)

1 Like

The first problem you have which is causing the error is that you need to use OpenCV >= 4.7.0 with CUDA >= 12.0 as texture references were removed in that version of CUDA.

The next problem you will have is that OpenCV DNN module (and possible others) is not compatible with CUDA 12.2 at the moment

I would advise you to upgrade to OpenCV 4.8.0 and use CUDA 12.1.


It’s unbelievable!, but my problem is solved. I tested many versions and I was almost disappointed. Thank you very much

I have multiple systems where CUDA 11.8 is required. Does it mean that I need to stick to OpenCV < 4.7? I don’t have a problem with that (as of now but who knows later) but I find it very difficult to determine (based on the release notes) which version would be compatible with CUDA 11.8. Even if I check 4.5 I still see “CUDA 12.0 support” in the notes.

No you should be fine with the latest version of OpenCV and CUDA 11.8. Support was added for CUDA 12.0 in 4.7.0 and CUDA 12.2 in the PR referenced above.