Caffe: Caffe Compilation Error: LD -o .build_release/lib/libcaffe.so.1.0.0-rc3 /usr/bin/ld: cannot find -lsnappy

Created on 20 Jul 2016  ·  20Comments  ·  Source: BVLC/caffe

I am compiling Caffe framework and i got this error while using the command make all. i have installed the prerequisite dependencies.

LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lsnappy
collect2: error: ld returned 1 exit status
Makefile:563: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

any help ???

Most helpful comment

make clean
make all
screenshot from 2017-09-04 17-41-59

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: cannot find -l -llmdb
collect2: error: ld returned 1 exit status
Makefile:575: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: * [.build_release/lib/libcaffe.so.1.0.0] Error 1
any one have solution thank you

All 20 comments

When you do cmake .., does it find snappy?

Check if you have libsnappy-dev installed, if not do this:
sudo apt-get install libsnappy-dev

thnx sir that one is solved but got this

CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
.build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)' .build_release/lib/libcaffe.so: undefined reference tocv::imencode(cv::String const&, cv::_InputArray const&, std::vector >&, std::vector > const&)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
collect2: error: ld returned 1 exit status
Makefile:616: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1

Looks like you don’t have opencv. Do this:
sudo apt-get install libopencv-dev

Or disable opencv while compiling caffe. Uncomment this in Makefile.config
USE_OPENCV := 0

same error tried both

CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
.build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)' .build_release/lib/libcaffe.so: undefined reference tocv::imencode(cv::String const&, cv::_InputArray const&, std::vector >&, std::vector > const&)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
collect2: error: ld returned 1 exit status
Makefile:616: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1

Can you share output of cmake with opencv disabled.

see the screenshot ? its with opencv disabled and i am using make not cmake

screenshot from 2016-07-20 23-13-08

Try using the "CMake Build" steps given in installation page.

If your OS is Ubuntu, you can follow the https://github.com/BVLC/caffe/issues and installed the dependencies, which include libsnappy-dev package.

cmake build worked for me thnx mate :+1:

From https://github.com/BVLC/caffe/blob/master/CONTRIBUTING.md:

_Please do not post usage, installation, or modeling questions, or other requests for help to Issues._
Use the caffe-users list instead. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe.

make clean
make all
screenshot from 2017-09-04 17-41-59

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: cannot find -l -llmdb
collect2: error: ld returned 1 exit status
Makefile:575: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: * [.build_release/lib/libcaffe.so.1.0.0] Error 1
any one have solution thank you

@Suraj59 I encountered the same error. have you found any solution for that?

I have a similar error with make instruction and cmake instruction does not help.
make error

CXX src/caffe/solver.cpp
CXX src/caffe/net.cpp
CXX src/caffe/internal_thread.cpp
CXX src/caffe/layer.cpp
CXX src/caffe/layer_factory.cpp
CXX src/caffe/data_transformer.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
CXX tools/upgrade_net_proto_binary.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
.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::base::CheckOpMessageBuilder::NewString()'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::DebugString() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::empty_string_'
.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::NameOfEnum(google::protobuf::EnumDescriptor const*, int)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(std::string const&, int)'
.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::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 `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::New()'
.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 `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:630: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1

My cmake compilation output error
cmake error

[ 83%] Building CXX object tools/CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o
[ 84%] Linking CXX executable compute_image_mean
CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o: In function `std::string* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)':
compute_image_mean.cpp:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x40): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o: In function `std::string* google::MakeCheckOpString<unsigned long, int>(unsigned long const&, int const&, char const*)':
compute_image_mean.cpp:(.text._ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringImiEEPSsRKT_RKT0_PKc]+0x41): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
CMakeFiles/compute_image_mean.dir/compute_image_mean.cpp.o: In function `main':
compute_image_mean.cpp:(.text.startup+0x12e): undefined reference to `google::SetUsageMessage(std::string const&)'
compute_image_mean.cpp:(.text.startup+0x22c): undefined reference to `google::protobuf::MessageLite::ParseFromString(std::string const&)'
compute_image_mean.cpp:(.text.startup+0x402): undefined reference to `google::protobuf::MessageLite::ParseFromString(std::string const&)'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::string*)'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::GetTypeName() const'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::DebugString() const'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::empty_string_'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFGetField@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptor const*, int)'
../lib/libcaffe.so.1.0.0: undefined reference to `cv::imread(std::string const&, int)'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFClose@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::Delete(std::string*)'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFOpen@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))'
../lib/libcaffe.so.1.0.0: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'
../lib/libcaffe.so.1.0.0: undefined reference to `cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFSetField@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::New()'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `leveldb::Status::ToString() const'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
collect2: error: ld returned 1 exit status
tools/CMakeFiles/compute_image_mean.dir/build.make:132: recipe for target 'tools/compute_image_mean' failed
make[2]: *** [tools/compute_image_mean] Error 1
CMakeFiles/Makefile2:467: recipe for target 'tools/CMakeFiles/compute_image_mean.dir/all' failed
make[1]: *** [tools/CMakeFiles/compute_image_mean.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

I fixed my problem partly by rebuidling protobuf and after rebuilding it "undefined reference to `google::protobuf ..." disappeared.

But I still have "undefined reference to google::base ..." , undefined reference toundefined reference to cv ..." undefined reference toleveldb ... " errors.

CXX src/caffe/internal_thread.cpp
CXX src/caffe/layer.cpp
CXX src/caffe/layer_factory.cpp
CXX src/caffe/data_transformer.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
CXX tools/upgrade_net_proto_binary.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
.build_release/lib/libcaffe.so: undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(std::string const&, int)'
.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 `cv::imencode(std::string const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
.build_release/lib/libcaffe.so: undefined reference to `leveldb::Status::ToString() const'
collect2: error: ld returned 1 exit status
Makefile:630: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1

I fixed this by using openblas instead of atlas.

@deepvid I have also got the same problem.
.
.
.
.
.CXX examples/cifar10/convert_cifar_data.cpp
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX .build_release/src/caffe/proto/caffe.pb.cc
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:554: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: * [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

And i did sudo apt-get install libhdf5-dev

Reading package lists... Done
Building dependency tree
Reading state information... Done
libhdf5-dev is already the newest version (1.8.16+docs-4ubuntu1)

What would be the problem?
Anyone faced the problem with this?
any solutions please

Hi,
I uncomment PKG_ CONFIG and it works

cmake build

hi,I meet the same error with you, I want to ask you how to use “cmake build”,thanks

@wajahatamin, I encountered the same error. how to use “cmake build”to solve it? thanks

i have this error
CXX src/caffe/layers/dummy_data_layer.cpp
CXX src/caffe/internal_thread.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so
/usr/bin/ld: cannot find -lsnappy
/usr/bin/ld: cannot find -lopencv_imagecodecs
/usr/bin/ld: cannot find -lsnappy
/usr/bin/ld: cannot find -l -llmdb
collect2: error: ld returned 1 exit status
Makefile:519: recipe for target '.build_release/lib/libcaffe.so' failed
make: * [.build_release/lib/libcaffe.so] Error 1

Was this page helpful?
0 / 5 - 0 ratings