gcc - 由于 gcc 编译器版本不受支持,Caffe 编译失败

标签 gcc cuda g++ caffe nvcc

我与 Caffe 作斗争汇编。不幸的是我没能编译它。

Steps我关注的是:

git clone https://github.com/BVLC/caffe.git
cd caffe
mkdir build
cd build
cmake ..
make all

运行 make all 失败并显示以下错误消息:

[  2%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile.dir/util/cuda_compile_generated_im2col.cu.o
In file included from /usr/include/cuda_runtime.h:59:0,
                 from <command-line>:0:
/usr/include/host_config.h:82:2: error: #error -- unsupported GNU version! gcc 4.9 and up are not supported!
 #error -- unsupported GNU version! gcc 4.9 and up are not supported!
  ^
CMake Error at cuda_compile_generated_im2col.cu.o.cmake:207 (message):
  Error generating /mydir/caffe/build/src/caffe/CMakeFiles/cuda_compile.dir/util/./cuda_compile_generated_im2col.cu.o

软件版本:

  • 操作系统:Debian
  • gcc版本:5.3.1
  • nvcc版本:6.5.12
  • cat/proc/driver/nvidia/version 结果:
NVRM version: NVIDIA UNIX x86_64 Kernel Module  352.63  Sat Nov  7 21:25:42 PST 2015
GCC version:  gcc version 4.8.5 (Debian 4.8.5-3) 
<小时/>

尝试解决问题

第一次尝试

简单的解决方案通常是最好的解决方案,因此(如建议的 here )我尝试注释掉 /usr/include/host_config.h 中的宏检查 gcc 版本(第 82 行)。不幸的是它不起作用并且编译严重失败:

1 catastrophic error detected in the compilation of "/tmp/tmpxft_000069c2_00000000-4_im2col.cpp4.ii".

第二次尝试

我尝试运行:

cmake -D CMAKE_CXX_COMPILER=g++-4.8 ..
make

但它失败了,完全相同相同的错误消息(即使应该接受g++-4.8)。

第三次尝试

我找到了similar problem (虽然与Caffe无关),我尝试按照已接受的答案中的建议解决它。

我做了什么:

  1. 我运行了 grep -iR "find_package(CUDA"caffe) 命令并发现 Cuda.cmake 文件,其中 225 行中有 find_package(CUDA 5.5 QUIET) .
  2. 我将 set(CUDA_HOST_COMPILER/usr/bin/gcc-4.8) 添加到 Cuda.cmake ,行前行:find_package(CUDA 5.5 QUIET)
  3. 我从 build 目录中删除了所有内容,并再次运行 cmakemake - 使用和不使用 -D CMAKE_CXX_COMPILER=g++-4.8

不幸的是结果是完全相同的。 Caffe 可能会以某种方式覆盖它 - 我不知道如何

make VERBOSE=1 2>&1 | grep -i compiler-bindir 不返回任何内容。

有趣的是,make VERBOSE=1 打印失败的命令,即:

/usr/bin/nvcc -M -D__CUDACC__ /mydir/caffe/src/caffe/util/im2col.cu -o /mydir/caffe/build/src/caffe/CMakeFiles/cuda_compile.dir/util/cuda_compile_generated_im2col.cu.o.NVCC-depend -ccbin /usr/bin/cc -m64 -DUSE_LMDB -DUSE_LEVELDB -DUSE_OPENCV -DWITH_PYTHON_LAYER -DGTEST_USE_OWN_TR1_TUPLE -Xcompiler ,\"-fPIC\",\"-Wall\",\"-Wno-sign-compare\",\"-Wno-uninitialized\",\"-O3\",\"-DNDEBUG\" -gencode arch=compute_20,code=sm_21 -Xcudafe --diag_suppress=cc_clobber_ignored -Xcudafe --diag_suppress=integer_sign_change -Xcudafe --diag_suppress=useless_using_declaration -Xcudafe --diag_suppress=set_but_not_used -Xcompiler -fPIC -DNVCC -I/usr/include -I/mydir/caffe/src -I/usr/include -I/mydir/caffe/build/include -I/usr/include/hdf5/serial -I/usr/include/opencv -I/usr/include/atlas -I/usr/include/python2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/mydir/caffe/include -I/mydir/caffe/build

当我手动添加 --compiler-bindir/usr/bin/gcc-4.8 标志时,它会打印错误:

nvcc fatal   : redefinition of argument 'compiler-bindir'

可能与this相关错误报告。

编辑:我没有注意到 --compiler-bindir-ccbin 是相同的选项,而后者已经是在上面的命令中设置失败。当我在上面失败的命令中将 -ccbin/usr/bin/cc 更改为 -ccbin/usr/bin/gcc-4.8 时,它成功完成。现在我需要在 Caffe 的 CMake 文件中找到覆盖所有后续 Caffe 的 CMake 中的 -ccbin 的选项。查看 cmake/Cuda.cmake:252:list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA} 似乎是个好方法。

<小时/>

如何才能成功完成编译?如有任何帮助,我们将不胜感激。

相关SO问题:

最佳答案

cmake -D CUDA_NVCC_FLAGS="-ccbin gcc-4.8".. && make 导致成功编译

<小时/>

现在出现了另一个问题:链接 Google 的 libgflagslibprotobuf 失败,可能是因为它是用较新的 gcc 版本编译的,但它是与提出的问题无关。

关于gcc - 由于 gcc 编译器版本不受支持,Caffe 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34403447/

相关文章:

c - 使用 malloc() 和 sizeof() 函数时出错

c++ - 指定流的内核启动,但具有默认的共享内存大小

c++ - gcc 4.8.2 和 gcc 4.9.0 在数组大小时的行为差异

ubuntu - C++0x_warning.h :31:2: error:

c++ - 使用已删除函数 - std::atomic

linux - 用于分析目的的编译选项

c - 为什么我的代码在 codechef (gcc 4.8.1) 上运行时显示运行时错误 (NZEC)?

c++ - CUDA C++ 链接错误 undefined reference threadIdx.x

python - CUDA 问题 - 如何在 Win 10 中清理安装 CUDA 以解决 cudaGetDevice() 失败

c++ - Clang 行指令