c++ - caffe 安装 : gcc error namespace "std" has no member "isnan"

标签 c++ ubuntu gcc caffe nvcc

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

然而,当我执行 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 个错误。

最佳答案

以我为例,我在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 

关于c++ - caffe 安装 : gcc error namespace "std" has no member "isnan",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47200632/

相关文章:

c++ - gcc -O4 优化标志

gcc - 减少 GCC 目标 EXE 代码大小?

c++ - 交换数组的两个元素后计数反转

c++ - 重载不适用于 <<

c++ - 如何制作 std::list 数组?

java - Linux,top 命令,为什么 "data"值和 jvm -xmx 参数不相等?

ubuntu - 如何使用 prisma (graphql) 集群

带变量的 C++ 幂函数

java - Ubuntu 上的 Ionic 在运行 "ionic emulate android"命令时出现 java 错误

linux - gcc的线程本地存储可以跨线程共享缓存线吗?