编译安装caffe

关于caffe安装过程中踩过的坑

首先,按照官网给出的东西安装依赖

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

我用的阿里云的源,这个里面有一个很坑的地方,依赖包下不下来。但是我并不知道到底是哪个包的安装除了问题,于是就一个一个往上装。装到libleveldb-dev的时候,报了下面这个错误

E: Failed to fetch http://172.21.0.163/files/200200000002F327/cdn.packages.deepin.com/deepin/pool/main/l/leveldb/libleveldb1v5_1.18-5_amd64.deb  Writing more data than expected (132633 > 132166)

E: Failed to fetch http://172.21.0.162/files/214400000002F323/cdn.packages.deepin.com/deepin/pool/main/l/leveldb/libleveldb-dev_1.18-5_amd64.deb  Writing more data than expected (174973 > 174456)

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

这里我从阿里的源换到东北大学的源就好了。继续往下安装,装到libopencv-dev的时候,再一次出现了跟上面原因差不多的问题。

E: Failed to fetch http://172.21.0.162/files/516900000000FE21/mirrordirector.raspbian.org/raspbian/pool/main/x/x11proto-input/x11proto-input-dev_2.3.1-1_all.deb  Writing more data than expected (141393 > 117618)

E: Failed to fetch http://172.21.0.162/files/316000000002F31A/cdn.packages.deepin.com/deepin/pool/main/libx/libxext/libxext-dev_1.3.3-1_amd64.deb  Writing more data than expected (82993 > 82090)

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

按照他的提示,用sudo apt-get update 还有sudo apt-get install libopencv-dev –fix-missing都不好使。然后我就把错误里两个deb直接下载下来安装。在用dpkb命令安装这两个包的时候,会报有些依赖没有安装的错误,这个时候只需要用apt-get install把这些依赖包装上就好了。
继续安装,blas我用的是这个命令 sudo apt-get install libatlas-base-dev
官方文档里面说Ubuntu14里需要 sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev ,而Ubuntu16没写,但是实际上Ubuntu16也需要这三个包。

接下来就是编译了。
在编译的过程中,出现了hdf5.h没有找到的错误。但是刚才明明已经装了hdf5。
根据网上的博客把Makefile.config和Makefile给改了就好了,当然在我的文件里不是这几行

解决方法
在Makefile.config文件的第85行,添加 /usr/include/hdf5/serial/ 到 INCLUDE_DIRS,也就是把下面第一行代码改为第二行代码。
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

在Makefile文件的第173行,把 hdf5_hl 和hdf5修改为hdf5_serial_hl 和 hdf5_serial,也就是把下面第一行代码改为第二行代码。
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

把WITH_PYTHON_LAYER打开以后会报找不到pyconfig.h的错误

CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin
.build_release/tools/extract_features.o: In function `std::string* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)':
extract_features.cpp:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x50): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
.build_release/tools/extract_features.o: In function `std::string* google::MakeCheckOpString<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)':
extract_features.cpp:(.text._ZN6google17MakeCheckOpStringImmEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringImmEEPSsRKT_RKT0_PKc]+0x51): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
...............省略掉n行
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::New()'
.build_release/lib/libcaffe.so: undefined reference to collect2: error: ld returned 1 exit status
`google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `leveldb::Status::ToString() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
collect2: error: ld returned 1 exit status
Makefile:627: recipe for target '.build_release/tools/upgrade_solver_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1
Makefile:627: recipe for target '.build_release/tools/compute_image_mean.bin' failed
make: *** [.build_release/tools/compute_image_mean.bin] Error 1

这个错误弄了好半天才弄好。因为原来的时候我编译别的东西的时候把gcc和g++都给换成4.9版本了,这次给它重新换成5.0就好了。在/usr/bin下可以看到这两个东西的版本,gcc命令实际上是一个软链接,把链接给改了就行了。
在编译pycaffe之前,anaconda是没有用的。。。因为在编译完成,准备去编译pycaffe的时候,发现它一直报错说找不到Python.h。然后看了一下Makefile.config,发现里面anaconda的路径写错了。
删掉以后再重新编译一遍,又报错了

.build_release/tools/net_speed_benchmark.o: In function `boost::system::system_error::what() const':
net_speed_benchmark.cpp:(.text._ZNK5boost6system12system_error4whatEv[_ZNK5boost6system12system_error4whatEv]+0x74): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
net_speed_benchmark.cpp:(.text._ZNK5boost6system12system_error4whatEv[_ZNK5boost6system12system_error4whatEv]+0xa1): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
net_speed_benchmark.cpp:(.text._ZNK5boost6system12system_error4whatEv[_ZNK5boost6system12system_error4whatEv]+0xe3): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgflags.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace_aux(unsigned long, unsigned long, unsigned long, char)@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)@GLIBCXX_3.4.21'
........省略n行

.build_release/lib/libcaffe.so: undefined reference to `std::logic_error::logic_error(std::logic_error const&)'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
.build_release/lib/libcaffe.so: undefined reference to `std::overflow_error::overflow_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
.build_release/lib/libcaffe.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char, unsigned long) const'
.build_release/lib/libcaffe.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
//usr/lib/x86_64-linux-gnu/libtbb.so.2: undefined reference to `std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgflags.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21'
.build_release/lib/libcaffe.so: undefined reference to `std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Makefile:627: recipe for target '.build_release/tools/extract_features.bin' failed
make: *** [.build_release/tools/extract_features.bin] Error 1

再次把anaconda的路径写错就又好了。感觉是anaconda里面不知道哪个包和系统的冲突了
总结一下,在编译pycaffe之前把anaconda注释掉或者把路径写错,在编译pycaffe的时候把路径改过来

之后,在Python中import caffe的时候,报错libstdc++.so.6: version `GLIBCXX_3.4.21' not found,这个时候,执行conda install libgcc就好了。
接下来, ImportError: No module named google.protobuf.internal,执行

pip install protobuf
sudo apt-get install python-protobuf

参考博客

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值