caffe安装:gcc错误命名空间“std”没有成员“isnan”

时间:2017-11-09 11:25:21

标签: c++ ubuntu gcc caffe nvcc

我正在尝试在ubuntu 17.10上安装(py)caffe

但是当我make all时,我收到以下错误:

./include/caffe/common.hpp(84): error: namespace "std" has no member "isnan"

./include/caffe/common.hpp(85): error: namespace "std" has no member "isinf"

2 errors detected in the compilation of "/tmp/tmpxft_00004921_00000000-19_nesterov_solver.compute_61.cpp1.ii".
Makefile:594: recipe for target '.build_release/cuda/src/caffe/solvers/nesterov_solver.o' failed

或当我使用cmake时

/home/thijser/caffe/include/caffe/common.hpp(84): error: namespace "std" has no member "isnan"

/home/thijser/caffe/include/caffe/common.hpp(85): error: namespace "std" has no member "isinf"

2 errors detected in the compilation of "/tmp/tmpxft_00004e32_00000000-7_math_functions.cpp1.ii".
CMake Error at cuda_compile_1_generated_math_functions.cu.o.Release.cmake:282 (message):
  Error generating file
  /home/thijser/caffe/build/src/caffe/CMakeFiles/cuda_compile_1.dir/util/./cuda_compile_1_generated_math_functions.cu.o

请注意,我不仅仅是为了sudo apt-get install caffe,因为这样做也不会安装pycaffe,任何安装pycaffe的解决方案也都有效。我知道std中的isnan可能来自boost或者这在某种程度上涉及c ++版本之间的差异?我不是一个c ++专家,所以我不确定它是如何工作的,我使用gcc4.9,因为nvcc不喜欢更高版本的gcc。我知道caffe适用于其他人的机器和我安装的旧版本的ubuntu,这表明它是一个配置问题。

有人知道如何解决这个问题吗?

在cmake上使用详细模式进行编辑我能够发现它正在执行以下操作

/usr/bin/cmake -E remove /home/thijser/caffe/build/src/caffe/CMakeFiles/cuda_compile_1.dir/util/cuda_compile_1_generated_math_functions.cu.o.depend.tmp /home/thijser/caffe/build/src/caffe/CMakeFiles/cuda_compile_1.dir/util/cuda_compile_1_generated_math_functions.cu.o.NVCC-depend
-- Generating /home/thijser/caffe/build/src/caffe/CMakeFiles/cuda_compile_1.dir/util/./cuda_compile_1_generated_math_functions.cu.o
/usr/bin/nvcc /home/thijser/caffe/src/caffe/util/math_functions.cu -c -o /home/thijser/caffe/build/src/caffe/CMakeFiles/cuda_compile_1.dir/util/./cuda_compile_1_generated_math_functions.cu.o -ccbin /usr/bin/cc -m64 -DCAFFE_VERSION=1.0.0 -Xcompiler ,\"-fPIC\",\"-Wall\",\"-Wno-sign-compare\",\"-Wno-uninitialized\",\"-O3\",\"-DNDEBUG\" -gencode arch=compute_61,code=sm_61 -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 -DUSE_LMDB -DUSE_LEVELDB -DUSE_OPENCV -DWITH_PYTHON_LAYER -Xcompiler -fPIC -DNVCC -I/home/thijser/caffe/include -I/home/thijser/caffe/src -I/usr/include -I/usr/include/hdf5/serial -I/usr/include/opencv -I/usr/include/x86_64-linux-gnu -I/usr/include/python2.7 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/home/thijser/caffe/build/include -I/home/thijser/caffe/build
/home/thijser/caffe/include/caffe/common.hpp(84): error: namespace "std" has no member "isnan"

/home/thijser/caffe/include/caffe/common.hpp(85): error: namespace "std" has no member "isinf"

针对以下代码进行测试: https://ideone.com/Yxvt5m

$ gcc -std = c ++ 11 test.cpp与g ++ test.cpp相同 给了我

test.cpp: In function ‘int main()’:
test.cpp:7:15: error: ‘__builtin_isnan’ is not a member of ‘std’
       cout << std::isnan(42.0) << std::isinf(42.0);
               ^
test.cpp:7:15: note: suggested alternative:
<built-in>: note:   ‘__builtin_isnan’
test.cpp:7:35: error: ‘__builtin_isinf_sign’ is not a member of ‘std’
       cout << std::isnan(42.0) << std::isinf(42.0);
                                   ^
test.cpp:7:35: note: suggested alternative:
<built-in>: note:   ‘__builtin_isinf_sign’

在我的机器上提出配置问题,但是clang ++ test.cpp没有给出任何错误,表明我们可以用它来安装caffe吗?

$ gcc --version

gcc (Ubuntu 4.8.5-4ubuntu6) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc -xc ++ -E -v -

Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.5-4ubuntu6' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.5 (Ubuntu 4.8.5-4ubuntu6) 
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE - -mtune=generic -march=x86-64 -fstack-protector -Wformat -Wformat-security
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

编辑:感谢@EliahKagan在askubuntu聊天中提出的建议,我发现在生成文件中添加CXXFLAGS + = g ++ -D_GLIBCXX_USE_C99_MATH -std = c ++ 11这一行解决了这个问题,但是它无疑会抛出下一个错误的

thijser@AI-core-Regain:~/caffe/build$ make all
[  0%] Building CXX object src/caffe/CMakeFiles/caffeproto.dir/__/__/include/caffe/proto/caffe.pb.cc.o
In file included from /home/thijser/caffe/build/include/caffe/proto/caffe.pb.cc:5:
/home/thijser/caffe/build/include/caffe/proto/caffe.pb.h:7:10: fatal error: 
      'string' file not found
#include <string>
         ^~~~~~~~

生成了1个错误。

3 个答案:

答案 0 :(得分:8)

就我而言,当我在ubuntu 17.10上构建caffe时,我也遇到了这个错误,但我终于找到了解决方案:

让我们添加以下内容:

的/ usr /包括/ x86_64的-Linux的GNU / C ++ / 5 /比特/ C ++的config.h

/* #undef _GLIBCXX_USE_C99_MATH */
#define  _GLIBCXX_USE_C99_MATH  1 

答案 1 :(得分:2)

经过与chat.askubuntu.com房间的几个人进行了长时间的详细讨论后,@ EliahKagan发现有一个python3-caffe-cuda包允许在python3中导入caffe。请注意,对于将来拥有python2的人来说,这不会解决这个问题,但对我而言,它可以工作。换句话说sudo apt-get install caffe然后使用python3而不是python2.7为我工作。

另请注意,我们发现底层问题似乎是gcc / g ++没有找到标准库(std)但是看起来clang和更高版本的gcc(gcc7)可以找到这些库但是这些库不会使用当前版本的nvcc。

答案 2 :(得分:0)

我很确定你应该设置正确的C ++标准。 std :: isnan是C ++ 11的一部分,较新的GCC默认使用此版本。较旧的仍默认为C ++ 98。

相关问题