Description
After switching to the current caffe version today, dynamic loading of several libraries, which contain different classifiers for specific tasks, does not work anymore. We've got the following error message:
[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: caffe.proto
Furthermore we are using Ubuntu 14.04 and the following version of libprotobuf:
/usr/lib/x86_64-linux-gnu/libprotobuf.so.8
/usr/lib/x86_64-linux-gnu/libprotobuf.so.8.0.0
Before updating caffe everything was fine and allows for loading of more than one library containing a caffe net. Seems as if the part of building the caffe specific proto header and cc-file has changed. Is there any conncetion to our problem? And how can we fix our problem?
Best, Tom
Activity
shelhamer commentedon Feb 20, 2015
There is a known issue with protobuf in loading dynamically linked libraries that all link to protobuf: https://code.google.com/p/protobuf/issues/detail?id=128. @longjon may be able to comment from his experience on this. A possible workaround is to combine your separate library-classifier combinations into a single library-classifiers arrangement with different calls for each model -- but in my own work I've only worked with a single
libcaffe.so
linked library that may execute different models depending on the calling code.TomKae commentedon Feb 21, 2015
Well, the point is, that it works fine until I've updated the caffe version yesterday and checked out the latest master (because of the modification of the net-constructor!). Even with the same protobuf version our implementation works with an older version of caffe on other 14.04 ubuntu systems we have. But this is a caffe version, we checked out by means of a snapshot (zip-file) more than half a year ago, so unfortunately we don't have any version number! But I already used a newer version, that also works in our framework with dynamic loading. Unfortunately I removed this trunk (before I checked out the current version) and thus I don't know its exact version.
We found out, that in the new caffe version, the CMakeList files and structure changed for building the protobuf files and part, respectively (in comparison to our old caffe snapshot!). So it seems, that these changes cause our trouble. I would like to test the last 2-3 caffe master versions. Is there a way to check out these older versions?
One more issue: Handling different classifiers in different libraries is a perfect way to allow for a flexible system structure, which is essential for a modular system concept. But even in this dynamic framework we only load "libcaffe.so" once which is a part of the main application. This is the usual way to handle shared objects.
shelhamer commentedon Feb 21, 2015
You can check out any version of the project since it is versioned through git. You can also look at our releases and pick a favorite.
#1667 overhauled the CMake build.
Right, that's sensible and fine -- what I was trying to say and why I linked the protobuf issue is that multiple libraries linked to protobuf (like Caffe classifiers) can conflict if they have a shared message. The protobuf issue suggests statically linking your classifier modules to libprotobuf. Earlier the whole Caffe project was static linked but we've switched to dynamic linking.
longjon commentedon Feb 21, 2015
You may want to try the
Makefile
/Makefile.config
build; at present the CMake build is still community-supported, so I can't offer specific help with that.The error you're getting does suggest that
libcaffe
is being loaded twice. You may want to check this withLD_DEBUG
.If you can produce a minimal non-working example using the
Makefile
build, I may be able to look into the issue.TomKae commentedon Feb 24, 2015
Thanks for you fast replies. We solved our problem, which was caused by linking the "libproto.a" to our dynamic libraries. This causes the above error and is not necessary anymore with the new caffe version. Now everything is fine and works. :-)
Thank you for your great support & best regards, Tom
tianzhi0549 commentedon Nov 22, 2015
Yep, linking caffe against libprotobuf.a instead of libprotobuf.so could solve this issue.
denny1108 commentedon Jan 13, 2016
@tianzhi0549 Can you show in details how to link caffe against libprotobuf.a instead of libprotobuf.so. Thank you so much.
tianzhi0549 commentedon Jan 14, 2016
@denny1108 I changed caffe's Makefile. Specifically, I added
-Wl,-Bstatic -lprotobuf -Wl,-Bdynamic
toLDFLAGS
and removedprotobuf
fromLIBRARIES
.I have uploaded my Makefile to gist(https://gist.github.com/tianzhi0549/773c8dbc383c0cb80e7b). You could check it out to see what changes I made (Line 172 and 369).
nbubis commentedon Jan 27, 2016
@tianzhi0549 Changing the Makefile gives:
LD -o .build_debug/lib/libcaffe.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libprotobuf.a(common.o): relocation R_X86_64_32S against `_ZTVN6google8protobuf7ClosureE' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libprotobuf.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
ANy ideas on how to solve this?
36 remaining items