Caffe安装:GCC错误命名空间“std”没有成员“isnan”。

4

我正在尝试在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聊天室中的建议,我发现在Makefile中添加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个错误。


如果有人知道我可以添加什么信息,我会很乐意添加! - Thijser
3
std::isnanstd::isinf是C++11的特性。gcc4.9默认使用c++98标准。你可能需要升级gcc或者在编译选项中添加-std=c++11 - n. m.
这是否会导致标志被添加到编译命令中?您能否使用您的gcc版本手动编译此代码(https://ideone.com/Yxvt5m)? - n. m.
1
如何检查:查看带有详细日志构建的cmake,参见此处。这是我得到的结果:您需要gcc -std=c++11 test.cpp - n. m.
1
顺便提一下,在 https://godbolt.org/ 上,我无法复现您在 gcc4.9 或任何其他版本的 gcc 中遇到的错误。 - n. m.
显示剩余17条评论
3个回答

9
在我的情况下,在ubuntu 17.10上构建caffe时,我也遇到了这个错误,但最后我找到了解决方法:
请将以下内容添加到:
/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h
/* #undef _GLIBCXX_USE_C99_MATH */
#define  _GLIBCXX_USE_C99_MATH  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不兼容。

0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接