caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Undefined reference to google protobuf

Open snavavf opened this issue 11 years ago • 64 comments

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

snavavf avatar Sep 09 '15 09:09 snavavf

If you are using Ubuntu, maybe this will help:

sudo apt-get install libprotobuf-dev protobuf-compiler

shibuyanorailgun avatar Sep 09 '15 15:09 shibuyanorailgun

I have already installed libprotobuf-dev and protobuf-compiler on my Ubuntu 14.04 yet still get those error messages.

snavavf avatar Sep 09 '15 15:09 snavavf

Perhaps add -pthread -lprotobuf -lpthread will do.

nr@linux ~ % pkg-config --libs protobuf
-pthread -lprotobuf -lpthread

shibuyanorailgun avatar Sep 09 '15 16:09 shibuyanorailgun

@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?

snavavf avatar Sep 10 '15 03:09 snavavf

= =, I'm sorry I can't figure out what happend.

shibuyanorailgun avatar Sep 10 '15 06:09 shibuyanorailgun

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

deepindeed2022 avatar Sep 22 '15 03:09 deepindeed2022

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.

antran89 avatar Oct 05 '15 07:10 antran89

Thanks @howtobeahacker ! That works.

snavavf avatar Oct 08 '15 07:10 snavavf

Can you explain me the solution? I am not sure to understand and I have a similar problem.

afarbos avatar Oct 14 '15 17:10 afarbos

FYI: This seems to be a perfect solution for me. http://stackoverflow.com/questions/10404027/cant-compile-example-from-google-protocol-buffers

tinoue avatar Nov 25 '15 07:11 tinoue

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.

ferrouswheel avatar Dec 05 '15 03:12 ferrouswheel

remove the gcc 5 error from the CUDA header host_config.h it works!

wadefelix avatar Jan 26 '16 11:01 wadefelix

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!

jay-to-the-dee avatar Feb 29 '16 22:02 jay-to-the-dee

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) */

netom avatar Mar 08 '16 09:03 netom

apparently someone called hottobeahacker solved this but i don't see that user or comment anymore. Could anyone enlighten me?

michaeljs1990 avatar May 01 '16 06:05 michaeljs1990

@michaeljs1990 It's me, I just changed my name. See my first comment in the thread, it might help you avoid the problem.

antran89 avatar May 03 '16 05:05 antran89

@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.

michaeljs1990 avatar May 03 '16 05:05 michaeljs1990

@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?

muzhi93 avatar May 10 '16 02:05 muzhi93

I encounter this problem too, but don't how to fix it

Holdlen2DH avatar Jun 18 '16 14:06 Holdlen2DH

This one works for me, in Ubuntu 16.04:

  1. Configure /usr/local/cuda/include/host_config.h as suggested.
  2. sudo apt-get autoremove libprotobuf-dev protobuf-compiler
  3. 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

wenwei202 avatar Jul 12 '16 17:07 wenwei202