近期在尝试跑LiteFlowNet,需要编译caffe,因为服务器上已经安装了CUDA11.3,其采用的环境是CUDA8.0+Cudnn5.1,因此安装了CUDA8.0的相关文件,并安装了gcc-4.8和g+±4.8。然而,在编译caffe时出现以下报错:
./include/caffe/parallel.hpp(99): warning: type qualifier on return type is meaningless
./include/caffe/parallel.hpp(99): warning: type qualifier on return type is meaningless
/usr/include/boost/system/error_code.hpp:233:21: error: looser throw specifier for ‘virtual const char* boost::system::error_category::std_category::name() const’
virtual const char * name() const BOOST_NOEXCEPT
^
/usr/include/c++/4.8/system_error:78:21: error: overriding ‘virtual const char* std::error_category::name() const noexcept (true)’
name() const noexcept = 0;
^
/usr/include/boost/system/error_code.hpp:243:37: error: looser throw specifier for ‘virtual std::error_condition boost::system::error_category::std_category::default_error_condition(int) const’
virtual std::error_condition default_error_condition( int ev ) const
^
/usr/include/c++/4.8/system_error:84:25: error: overriding ‘virtual std::error_condition std::error_category::default_error_condition(int) const noexcept (true)’
default_error_condition(int __i) const noexcept;
^
/usr/include/boost/system/error_code.hpp:245:21: error: looser throw specifier for ‘virtual bool boost::system::error_category::std_category::equivalent(int, const std::error_condition&) const’
virtual bool equivalent( int code, const std::error_condition & condition ) const
^
/usr/include/c++/4.8/system_error:87:14: error: overriding ‘virtual bool std::error_category::equivalent(int, const std::error_condition&) const noexcept (true)’
equivalent(int __i, const error_condition& __cond) const noexcept;
^
/usr/include/boost/system/error_code.hpp:247:21: error: looser throw specifier for ‘virtual bool boost::system::error_category::std_category::equivalent(const std::error_code&, int) const’
virtual bool equivalent( const std::error_code & code, int condition ) const
^
/usr/include/c++/4.8/system_error:90:14: error: overriding ‘virtual bool std::error_category::equivalent(const std::error_code&, int) const noexcept (true)’
equivalent(const error_code& __code, int __i) const noexcept;
^
Makefile:590: recipe for target '.build_release/cuda/src/caffe/layers/correlation_layer1d.o' failed
make: *** [.build_release/cuda/src/caffe/layers/correlation_layer1d.o] Error 1
make: *** 正在等待未完成的任务....
在网上找了很久的解决方案,但是资料太少,仅有的一篇回答是需要在/usr/include/boost/config/compile/nvcc.hpp中添加
# define BOOST_NO_CXX11_NOEXCEPT
遂尝试了一下,发现没有任何效果。之后,偶然看到关于改进boost代码的一个帖子,其中为了在CUDA8.0下禁用c++11的部分代码,boost作者在nvcc.hpp文件中添加了以下语句:
#if (BOOST_CUDA_VERSION >= 8000000) && (BOOST_CUDA_VERSION < 8010000)
# define BOOST_NO_CXX11_NOEXCEPT
#endif
然而,虽然我在编译caffe时使用CUDA8.0,但是系统默认CUDA是11.3,所以在进行boost时会使用到C++11的代码,因此将本段代码注释,即可解决问题:
//#if (BOOST_CUDA_VERSION >= 8000000) && (BOOST_CUDA_VERSION < 8010000)
//# define BOOST_NO_CXX11_NOEXCEPT
//#endif