编译caffe_yolov5

遇到的问题:

CXX/LD -o .build_release/tools/extract_features.bin
.build_release/lib/libcaffe.so: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
.build_release/lib/libcaffe.so: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
.build_release/lib/libcaffe.so: undefined reference to `leveldb::Status::ToString() const'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
make: *** [.build_release/tools/caffemodel2txt.bin] Error 1
...省略n行
.build_release/lib/libcaffe.so: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::Makefile:637: recipe for target '.build_release/tools/caffe_yolov5s.bin' failed
stringmake: *** [.build_release/tools/caffe_yolov5s.bin] Error 1
 const&, leveldb::DB**)'
.build_release/lib/libcaffe.so: undefined reference to `leveldb::Status::ToString() const'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1

安装了leveldb
https://blog.csdn.net/qq_20965753/article/details/77033300
https://blog.csdn.net/a1165741556/article/details/104028855?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-12.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-12.no_search_link
安装时遇到报错:升级gcc为7.5
https://blog.csdn.net/qq_43140627/article/details/119766876

cp build/libleveldb.a /usr/local/lib/
cp -r include/leveldb/ /usr/local/include/

还把其他路径找到的libleveldb.so libleveldb.so.1 libleveldb.so.1.20 拷贝到/usr/local/lib , 将include/*拷贝到/usr/local/include, 即拷贝leveldb文件夹. sudo ldconfig

但是没用。又根据教程:https://www.freesion.com/article/1878253612/
https://blog.csdn.net/mhsszm/article/details/88745120
尝试了各种gcc版本,还是不成功。
修改了makefile.config:
https://github.com/BVLC/caffe/issues/4949

又尝试了:https://blog.csdn.net/ph_153/article/details/101446725

1 cd && cd leveldb/
2 sudo cp libleveldb.a /usr/local/bin/
3 sudo cp -r include/leveldb/ /usr/local/include/

4 sudo cp /usr/local/bin/libleveldb.a /usr/bin/

参考:http://cn.voidcc.com/question/p-ocenillg-ns.html
把USE_LEVELDB“Build with levelDB”在CMakeLists中变为OFF,编译还是报错。
最后都没有解决问题。

根据教程:https://blog.csdn.net/jyl1999xxxx/article/details/80583465
重新安装了leveldb-1.9.0
然后报错:

CXX/LD -o .build_release/tools/extract_features.bin
.build_release/lib/libcaffe.so: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
make: *** Waiting for unfinished jobs....
.build_release/lib/libcaffe.so: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/upgrade_solver_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1
.build_release/lib/libcaffe.so: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/caffemodel2txt.bin' failed
make: *** [.build_release/tools/caffemodel2txt.bin] Error 1
...省略n行
.build_release/tools/caffe.o:caffe.cpp:(.text.startup+0x6ab): more undefined references to `google::FlagRegisterer::FlagRegisterer<std::string>(char const*, char const*, char const*, std::string*, std::string*)' follow
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1

根据:https://www.freesion.com/article/8200828393/
原先安装的glog, gflags等依赖库;然后使用GCC 4.9 手动编译glob,gflags等依赖库。具体方法参考Caffe官方教程:Ubuntu Installation
安装glog-0.3.3时报错:

又根据:https://blog.csdn.net/u012825187/article/details/85696512
安装glob,gflags失败。

按照:https://blog.csdn.net/qq_33202928/article/details/89884924,说是protoc安装时候的gcc版本和目前编译使用的gcc版本不一致所致。于是尝试:
分别在gcc-4.8下重新安装protoc,并编译还是一样报错。
又在gcc-5.5下重新安装protoc,并编译问题好像解决了,报其他的错。这里注意编译protoc的时候先meke clean一下。我第一次没有make clean,问题没有解决,后来又重新装了一遍。又报错,所以是gcc-4.8.5下安装protoc-2.6.1并编译caffe报上边的错,gcc-5.4下安装protoc-2.6.1并编译caffe报下边的错。

.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::GetTypeName() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::Delete(std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::DebugString() const'
.build_release/lib/libcaffe.so: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::New()'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageLite::ParseFromString(std::string const&)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::empty_string_'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptor const*, int)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
make: *** Waiting for unfinished jobs....
.build_release/tools/convert_imageset.o: In function `std::string* google::MakeCheckOpString<unsigned long, int>(unsigned long const&, int const&, char const*)':
...省略n行。
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/extract_features.bin' failed
make: *** [.build_release/tools/extract_features.bin] Error 1
.build_release/tools/caffe.o: In function `train()':
caffe.cpp:(.text+0x262a): undefined reference to `google::protobuf::internal::StringTypeHandlerBase::New()'
caffe.cpp:(.text+0x3563): undefined reference to `google::p
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::GetTypeName() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::Delete(std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::DebugString() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageLite::ParseFromString(std::string const&)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::empty_string_'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptor const*, int)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1

又改成gcc-5.4下安装protoc-2.5.0,并编译caffe,又报错:

..build_release/libbuild_release//libcaffe.so:lib undefined/ referencelibcaffe.so to: ` googleundefined: :protobufreference: :internalto: :WireFormatLite`:google:ReadString:(:google:protobuf::protobuf::internal::io:::WireFormatLiteCodedInputStream:*:,ReadString (stdgoogle:::string:*protobuf):':
io.:build_release:/libCodedInputStream/*libcaffe.so,:  undefinedstd :reference: tostring *`)google'::
protobuf.:build_release:/Messagelib:/:libcaffe.soGetTypeName:( ) undefinedconst 'reference
 .build_releaseto/ lib`/googlelibcaffe.so::: protobufundefined: :referenceMessage :to: `GetTypeNamegoogle(:): protobufconst:':
internal.::build_releaseStringTypeHandlerBase/:lib:/Delete(libcaffe.sostd::: stringundefined* )reference' 
to. build_release`/googlelib:/:libcaffe.soprotobuf:: :undefinedinternal :reference: toStringTypeHandlerBase :`:googleDelete:(:stdprotobuf::::internalstring:*:)kEmptyString'

又根据:https://www.codetd.com/article/4145133
把所有的protoc都卸载,重新在gcc-5.5.0下安装protoc-2.6.1,和上边报一样的错::WireFormatLite::WriteStringMaybeAliased
把所有的protoc都卸载,重新在gcc-4.8.5下安装protoc-2.6.1,和之前报一样的错:
undefined reference to `google::base::CheckOpMessageBuilder::NewString()’

崩溃了…
最后还是去安装gflags和glog。

注意编译顺序,应该是先编译gflags,然后再编译glog。
1.gflags

wget https://github.com/schuhschuh/gflags/archive/master.zip 
unzip master.zip 
cd gflags-master 
mkdir build && cd build 
export CXXFLAGS="-fPIC"
cmake ..
make VERBOSE=1
make
make install

2.glog
csdn下载地址:http://download.csdn.net/detail/chenguangxing3/6661667
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure
make
make install
但是这里make的时候报错:

logging_unittest-logging_unittest.o: In function `__static_initialization_and_destruction_0(int, int)':
logging_unittest.cc:(.text+0xe68a): undefined reference to `google::FlagRegisterer::FlagRegisterer<std::string>(char const*, char const*, char const*, std::string*, std::string*)'
logging_unittest.cc:(.text+0xe74d): undefined reference to `google::FlagRegisterer::FlagRegisterer<std::string>(char const*, char const*, char const*, std::string*, std::string*)'
collect2: error: ld returned 1 exit status
Makefile:750: recipe for target 'logging_unittest' failed
make: *** [logging_unittest] Error 1

于是又用:
git clone https://github.com/google/glog.git
cd glog/
:~/software/glog$ mkdir build
:~/software/glog$ cd build/
:~/software/glog/build$ cmake …
~/software/glog/build$ make
~/software/glog/build$ sudo make install
参考:http://www.voidcn.com/article/p-nstyyexd-bdx.html
https://blog.csdn.net/u012825187/article/details/85696512

最后编译make all -j8终于成功了,花了将近两天的时间。

运行pycaffe时,报错找不到libglog.so.1

~$ ln -s /home/zl/software/glog/build/libglog.so.1 /usr/lib

报错:

Boost.Python.ArgumentError:Python argument types in
Net.__init__(Net,str, str, int)
did notmatch C++ signature:
__init__(boost::python::api::object,std::string, std::string, int)
__init__(boost::python::api::object,std::string, int)

按照https://github.com/BVLC/caffe/issues/3220修改

报错:

Boost.Python.ArgumentError: Python argument types in
    None.save(Net, str)
did not match C++ signature:
    save(caffe::Net<float>, std::string)

修改:

shared_ptr<Net<Dtype> > Net_Init_Load(
//    string param_file, string pretrained_param_file, int phase) {
    char* param_file, char* pretrained_param_file, int phase) {
// shared_ptr<Net<Dtype> > Net_Init(string network_file, int phase,
shared_ptr<Net<Dtype> > Net_Init(char* network_file, int phase,
    const int level, const bp::object& stages,
//void Net_Save(const Net<Dtype>& net, string filename) {
void Net_Save(const Net<Dtype>& net, char* filename) {
  NetParameter net_param;
  net.ToProto(&net_param, false);
//  WriteProtoToBinaryFile(net_param, filename.c_str());
  WriteProtoToBinaryFile(net_param, filename);	
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值