完整报错
/var/docker/opencv-4.5.0/opencv_contrib-4.5.0/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(61): error: texture is not a template
/var/docker/opencv-4.5.0/opencv_contrib-4.5.0/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(83): error: identifier "cudaUnbindTexture" is undefined
/var/docker/opencv-4.5.0/modules/core/include/opencv2/core/cuda/common.hpp(99): error: identifier "textureReference" is undefined
[ 15%] Building C object 3rdparty/libwebp/CMakeFiles/libwebp.dir/src/dsp/upsampling_sse41.c.o
3 errors detected in the compilation of "/var/docker/opencv-4.5.0/modules/core/src/cuda/gpu_mat.cu".
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.RELEASE.cmake:282 (message):
Error generating file
/var/docker/opencv-4.5.0/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/build.make:77: modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4078: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
问题根因
这是由于cuda的版本问题造成的,下面介绍方案
解决方案1
如果你的cuda版本是11.x,在opencv 4.5.0的项目根目录的CMakelists.txt的开头加一句
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")
参考:Ubuntu16.05+CUDA8下编译OpenCV错误 [...cuda_compile_generated_gpu_mat.cu.o] Error 1
没有验证过,如果有同学验证过,并成功了。希望在评论区积极反馈
解决方案2
如果你的cuda版本是12.x,提供两个选择
- 要么选择降级cuda为11.x,而继续编译opencv4.5.0
- 要么选择升级opencv为4.8.0版本(亲测有效),而继续使用cuda12.x
参考:Build OpenCV with CUDA 12, undefined identifiers cudaUnbindTexture, textureReference
源文划重点:
CUDA 12.0 dropped support for legacy texture references. Therefore, any code that uses legacy texture references can no longer be properly compiled with CUDA 12.0 or beyond.
Legacy texture reference usage has been deprecated for some time now.
As indicated in the comments, by reverting to CUDA 11.x where legacy texture references are still supported (albeit deprecated) you won't run into this issue.
The other option may happen some day when OpenCV converts usage of legacy texture references to texture object methods. In that case, it may then be possible to use CUDA 12.0 or a newer CUDA toolkit to compile OpenCV/CUDA functionality.
There is no work around to somehow allow texture reference usage to be compiled properly with CUDA 12.0 and beyond.
Likewise, this limitation is not unique or specific to OpenCV. Any CUDA code that uses texture references can no longer be compiled properly with CUDA 12.0 and beyond. The options are to refactor that code with texture object usage instead, or revert to a previous CUDA toolkit that still has the deprecated support for texture reference usage.
源文重点处翻译
CUDA 12.0 放弃了对旧纹理引用的支持。 因此,任何使用旧版纹理引用的代码都无法再使用 CUDA 12.0 或更高版本正确编译。
旧版纹理参考用法已被弃用一段时间了。
如评论中所示,通过恢复到仍支持旧纹理引用(尽管已弃用)的 CUDA 11.x,您将不会遇到此问题。
当 OpenCV 将旧纹理引用的使用转换为纹理对象方法时,有一天可能会出现另一种选择。 在这种情况下,可以使用 CUDA 12.0 或更新的 CUDA 工具包来编译 OpenCV/CUDA 功能。
没有解决方法可以以某种方式允许使用 CUDA 12.0 及更高版本正确编译纹理参考使用。
同样,这个限制并不是 OpenCV 独有的或特定的。 任何使用纹理引用的 CUDA 代码都无法再使用 CUDA 12.0 及更高版本正确编译。 这些选项是使用纹理对象使用来重构该代码,或者恢复到以前的 CUDA 工具包,该工具包仍然具有对纹理引用使用的已弃用支持
希望各位同学,能在评论区多多交流,相互避坑。文章来源:https://www.toymoban.com/news/detail-832123.html
关于在编译opencv的其它问题,多是一些文件下载问题,网上有很多可以参考的地方,在此处就不再赘述。文章来源地址https://www.toymoban.com/news/detail-832123.html
到了这里,关于opencv 编译cuda版本 error: “cudaUnbindTexture“ is undefined cuda_compile_1_generated_gpu_mat.cu.o的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!