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

Caffe compilation fails due to unsupported gcc compiler version

我在 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

软件版本:

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(第 82 行)中注释掉宏检查 gcc 版本。不幸的是它不起作用并且编译严重失败:

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 应该被接受)。

第三次尝试

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

我做了什么:

  1. 我已经 运行 grep -iR "find_package(CUDA" caffe 命令并找到了 Cuda.cmake file which has find_package(CUDA 5.5 QUIET) in line 225
  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 returns 没有。

有趣的是,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 版本编译的,但事实并非如此与问题相关。

我的机器运行 Ubuntu 15.10,我的默认编译器版本是 gcc 5.2.1。

注释掉文件第 115 行的#error 指令

/usr/local/cuda-7.5/include/host_config.h 

(或您系统上的任何路径)对我有用。 Caffe编译正常,所有测试运行顺利。

另一方面,如果选择忽略这一点并继续使用一个编译器版本编译项目的一部分,则使用另一个编译器版本编译项目的一部分(对我来说是 gcc-4.8 和 gcc-5.2.1) ,就会出现连接问题。另一个答案提到的 protobuf 和 libgflags 的链接问题 not 与此无关。