Ubuntu20+CUDA11编译Caffe时遇cudaGetDeviceProperties_v2未定义引用错误
解决Ubuntu 20 + CUDA 11编译Caffe时
cudaGetDeviceProperties_v2未定义引用的问题 替换旧版CUDA API调用
CUDA 11已经废弃了带_v2后缀的旧版设备属性查询API,直接把代码中所有cudaGetDeviceProperties_v2替换成cudaGetDeviceProperties即可。可以用命令全局搜索替换:grep -r "cudaGetDeviceProperties_v2" ./caffe-source-dir/ sed -i 's/cudaGetDeviceProperties_v2/cudaGetDeviceProperties/g' ./caffe-source-dir/$(grep -r "cudaGetDeviceProperties_v2" ./caffe-source-dir/ | cut -d: -f1)修正Makefile.config中的CUDA配置
打开Makefile.config,确保以下配置正确指向CUDA 11的路径和支持的GPU架构:CUDA_INCLUDE_DIRS := /usr/local/cuda-11.x/include CUDA_LIB_DIRS := /usr/local/cuda-11.x/lib64 # 根据你的GPU型号调整,比如RTX 20/30系列用compute_75,40系列用compute_89 CUDA_ARCH := -gencode arch=compute_75,code=sm_75 \ -gencode arch=compute_80,code=sm_80 \ -gencode arch=compute_86,code=sm_86确认链接阶段正确关联CUDA库
检查Makefile中的LIBRARIES配置,确保包含cudart等必要的CUDA库:LIBRARIES += cudart cublas curand清理缓存重新编译
先清除旧的编译产物,避免缓存干扰,再重新编译:make clean make all -j$(nproc)适配CUDA 11的分支/补丁
如果官方原版Caffe对CUDA 11支持不足,可以切换到社区维护的适配CUDA 11的分支,或者应用对应的适配补丁,解决API兼容性问题。
内容的提问来源于stack exchange,提问作者Planck35
相关产品推荐
相关产品推荐

