Undefined reference to google protobuf
I got these errors saying there are undefined reference to google protobuf when make all in caffe dir.
I wonder which file (like the Makefile?) I should modify, or where I should set up in my system.
I've already installed protobuf as the command provided in the link, and installed libprotobuf-dev and protobuf-compiler on my Ubuntu 14.04.
CXX/LD -o .build_release/tools/convert_imageset.bin
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteVarint64ToArray(unsigned long long, unsigned char*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteInt64(int, long long, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::UnknownFieldSet::AddVarint(int, unsigned long long)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::VarintSize64(unsigned long long)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteVarint64(unsigned long long)'
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/convert_imageset.bin] Error 1
If you are using Ubuntu, maybe this will help:
sudo apt-get install libprotobuf-dev protobuf-compiler
I have already installed libprotobuf-dev and protobuf-compiler on my Ubuntu 14.04 yet still get those error messages.
Perhaps add -pthread -lprotobuf -lpthread will do.
nr@linux ~ % pkg-config --libs protobuf
-pthread -lprotobuf -lpthread
@shibuyanorailgun I don't quite understand... I think -lprotobuf is already handled at line 172 and line 364 at Makefile,
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \
$(foreach library,$(LIBRARIES),-l$(library))
and -pthread is handled at line 352.
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
I tried to edit line 172 to
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc pthread
but that doesn't help.
I don't know much about Makefile, so maybe I misunderstood. Could you explain more about how to compile it right?
= =, I'm sorry I can't figure out what happend.
I encountered trouble alike I encountered trouble alike, see buildlog as follow: PROTOC src/caffe/proto/caffe.proto make: protoc: Command not found make: *** [.build_release/src/caffe/proto/caffe.pb.h] Error 127 thanks for your answer @shibuyanorailgun
Hi @snavavf, @cwlseu,
[UPDATED, DO NOT TRY THIS]Please try to remove the os versions of protobuf in /usr/lib/x86_64-linux-gnu. (Something like libprotobuf.*, libprotobuf-lite.*, libprotoc.*). There are two versions of protobuf will cause conflicts when compiling.
Then try to install newest version of protobuf.
Better versions: [UPDATED, TRY THIS] Instead of my bad advice on deleting with system files, we can remove development files of libprotobuf but still keep library files in /usr/lib/x86_64-linux-gnu by this command
apt-get remove libprotobuf-dev
Then try to install newest version of protobuf.
Thanks @howtobeahacker ! That works.
Can you explain me the solution? I am not sure to understand and I have a similar problem.
FYI: This seems to be a perfect solution for me. http://stackoverflow.com/questions/10404027/cant-compile-example-from-google-protocol-buffers
Advising people to delete system libraries isn't an ideal solution.
I tried to remove protobuf-lite in ubuntu 15.10 with sudo apt-get remove libprotobuf-lite9v5 (because I don't want to break my system) but it tries to remove 205 other packages (including my desktop).
Googling about this reminded me that I had previously tryed to make CUDA work by changing to gcc 4.9. Unfortunately the c++ ABI changed so compiling stuff with 4.9 and trying to link to system libraries built with gcc 5 won't work.
On the mailing list people are suggesting to remove the gcc 5 error from the CUDA header /usr/local/cuda/include/host_config.h.
remove the gcc 5 error from the CUDA header host_config.h
it works!
This appears to be a prevalent issue ob Ubuntu 15.10! Caffe used to work fine on 15.04! Also I'm using CUDA 7.5 so in theory I should be fine for the GCC version issue!
Hi, Ubuntu 15.10 user here. Had the same issue, solved by patching CUDA (/usr/local/cuda/include/host_config.h).
Diff:
< #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9)
---
> //#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9)
115c115
< #error -- unsupported GNU version! gcc versions later than 4.9 are not supported!
---
> //#error -- unsupported GNU version! gcc versions later than 4.9 are not supported!
117c117
< #endif /* __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) */
---
> //#endif /* __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) */
apparently someone called hottobeahacker solved this but i don't see that user or comment anymore. Could anyone enlighten me?
@michaeljs1990 It's me, I just changed my name. See my first comment in the thread, it might help you avoid the problem.
@antran89 thanks for the response. Unfortunately I have to use protoc 2.5 with my project so that is a no go for me. It seems that this library no longer works with the stock ubuntu 14.04 packages and the website contains incorrect information for building this package as well.
@antran89 Hi,following your guidance,I've successfully compiled Caffe,but there is another problem arising:when I reboot my machine,the leftside toolbar of my ubuntu 14.04 desktop is gone,then I typed ccsm in the command window,which reported an error,ImportError: libprotobuf.so.8: cannot open shared object file: No such file or directory.I wonder whether it is because I deleted the OS's protobuf file that lead to the breakdown of my desktop?
I encounter this problem too, but don't how to fix it
This one works for me, in Ubuntu 16.04:
- Configure
/usr/local/cuda/include/host_config.has suggested. sudo apt-get autoremove libprotobuf-dev protobuf-compiler- then compile the protobuf-2.5.0 from src and install
Please config the gcc when you compile protobuf
./configure --prefix=/usr/local/ CC=/usr/bin/gcc