joshivineet / protobuf

Automatically exported from code.google.com/p/protobuf
Other
0 stars 0 forks source link

Unnecessary dependency against protobuf in third-level targets. #657

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have C++ generated file, say `a.pb.cc`, and I link it into shared library 
`a.so`. This library is also linked against `libprotobuf.so`.

When I do include `a.pb.h` in another file, say `test.cc`, I can't link it into 
executable `test` without adding dependency on `libprotobuf.so`: otherwise, I 
get undefined symbols errors, like:

"google::protobuf::internal::RepeatedPtrFieldBase::Reserve(int)"
"google::protobuf::internal::kEmptyString"
"google::protobuf::internal::ExtensionSet::ReleaseMessage(int, 
google::protobuf::MessageLite const&)"
"google::protobuf::internal::ExtensionSet::MutableMessage(int, unsigned char, 
google::protobuf::MessageLite const&, google::protobuf::FieldDescriptor const*)"

The sum-up of dependencies:

1) test (test.cc includes a.pb.h) depends on a.so (a.pb.cc includes a.pb.h)
2) a.so (a.pb.cc includes a.pb.h) depends on libprotobuf.so
3) test (test.cc includes a.pb.h) depends on libprotobuf.so (!)

The possible reason is that I don't know enough about the linking.
The other possible reason is a design flaw in generated files - I don't see any 
particular reason to link against protobuf every target that already links 
against generated protobuf files or just includes some .pb.h

Original issue reported on code.google.com by abys...@gmail.com on 20 Jul 2014 at 8:22