构建OpenCV的基本CMakefile问题

Basic CMakefile question for building OpenCV

本文关键字:CMakefile 问题 OpenCV 构建      更新时间:2023-10-16

我是C++编程新手,现在必须从源代码构建OpenCV。我收到与 cudatoolkit 安装相关的错误

[ 13%] Built target opencv_cudev
[ 13%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
nvcc fatal   : Path to libdevice library not specified
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message):
Error generating file
/home/bruce/opencv-4.2.0/build/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

我查看cuda_compile_generated_gpu_mat.cu.o.cmake文件内部,看到以下行。

# Generate the code
cuda_execute_process(
"Generating ${generated_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${format_flag} -o "${generated_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${CUDA_NVCC_FLAGS}
-DNVCC
${CUDA_NVCC_INCLUDE_ARGS}
)

我想深入研究它在哪里寻找 libdevice 库。我不知道打印出所有这些参数含义的技术。如何在执行make时打印它们?

如果要调试此变量并打印每个 CMake 变量中的值,可以将message命令添加到此 CMake 文件中:

# Generate the code
cuda_execute_process(
"Generating ${generated_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${format_flag} -o "${generated_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${CUDA_NVCC_FLAGS}
-DNVCC
${CUDA_NVCC_INCLUDE_ARGS}
)
# Print all the above variables to the console.
message("generated_file: ${generated_file}")
message("CUDA_NVCC_EXECUTABLE: ${CUDA_NVCC_EXECUTABLE}")
message("source_file: ${source_file}")
message("format_flag: ${format_flag}")
message("CCBIN: ${CCBIN}")
message("nvcc_flags: ${nvcc_flags}")
message("nvcc_host_compiler_flags: ${nvcc_host_compiler_flags}")
message("CUDA_NVCC_FLAGS: ${CUDA_NVCC_FLAGS}")
message("CUDA_NVCC_INCLUDE_ARGS: ${CUDA_NVCC_INCLUDE_ARGS}")

如果可以修改从命令行调用cmake的方式,则可以添加trace-expand选项以打印所有 CMake 调用,并展开使用的变量:

cmake --trace-expand ..