Creating Static C++ Library with Protobuf messages to be reused accross projects

1,068 views
Skip to first unread message

c.co...@axis-canada.com

unread,
Mar 21, 2018, 2:13:47 PM3/21/18
to Protocol Buffers
Hi,

I am trying to create a static lib with the message definitions to be share across multiple CMake projects. At the moment, I have:
  • A Conan.io package with protobuf pre-comiled into static libs.
  • A CommonDefinitions project (with a dependency to the protobuf package)
    • From which I create a CommonDefinitions conan.io package containing the CommonDefinitions static library
    • Project include a test Executable which uses the static library
  • A EndUser project (with a dependency to the CommonDefinitions package and the protobuf package)
Now, the test executable of the CommonDefiniitons project works as expected and has access to the CommonDefinitions messages. However, the EndUser project is not able to link, it complains about missing references to protobuf static libraries, even though I also include the protobuf package in the EndUser target_link_libraries project as well.

Does anyone have an idea or had a similar problem?

Thanks

Here are the linker traces:

/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `protobuf_test_2eproto::protobuf_AssignDescriptors()':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:79: undefined reference to `google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `protobuf_test_2eproto::protobuf_RegisterTypes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:90: undefined reference to `google::protobuf::internal::RegisterAllTypes(google::protobuf::Metadata const*, int)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `protobuf_test_2eproto::AddDescriptorsImpl()':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:101: undefined reference to `google::protobuf::DescriptorPool::InternalAddGeneratedFile(void const*, int)'
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:103: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `axis::system::test::TestData::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*)':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:251: undefined reference to `google::protobuf::internal::WireFormat::SkipField(google::protobuf::io::CodedInputStream*, unsigned int, google::protobuf::UnknownFieldSet*)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `axis::system::test::TestData::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:294: undefined reference to `google::protobuf::internal::WireFormat::SerializeUnknownFields(google::protobuf::UnknownFieldSet const&, google::protobuf::io::CodedOutputStream*)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `axis::system::test::TestData::InternalSerializeWithCachedSizesToArray(bool, unsigned char*) const':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:330: undefined reference to `google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(google::protobuf::UnknownFieldSet const&, unsigned char*)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `axis::system::test::TestData::ByteSizeLong() const':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:343: undefined reference to `google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(google::protobuf::UnknownFieldSet const&)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `axis::system::test::TestData::MergeFrom(google::protobuf::Message const&)':
/home/toto/gitlab/system/system-definitions/build-debug/Definitions/test.pb.cc:374: undefined reference to `google::protobuf::internal::ReflectionOps::Merge(google::protobuf::Message const&, google::protobuf::Message*)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::MessageLite::MessageLite()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/message_lite.h:176: undefined reference to `vtable for google::protobuf::MessageLite'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::MessageLite::~MessageLite()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/message_lite.h:177: undefined reference to `vtable for google::protobuf::MessageLite'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::internal::GetProto3PreserveUnknownsDefault()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/message_lite.h:400: undefined reference to `google::protobuf::internal::proto3_preserve_unknown_'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::UnknownFieldSet::Clear()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/unknown_field_set.h:267: undefined reference to `google::protobuf::UnknownFieldSet::ClearFallback()'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::internal::InternalMetadataWithArena::DoMergeFrom(google::protobuf::UnknownFieldSet const&)':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/metadata.h:62: undefined reference to `google::protobuf::UnknownFieldSet::MergeFrom(google::protobuf::UnknownFieldSet const&)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::internal::InternalMetadataWithArena::default_instance()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/metadata.h:70: undefined reference to `google::protobuf::UnknownFieldSet::default_instance()'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::Message::Message()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/message.h:188: undefined reference to `vtable for google::protobuf::Message'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `google::protobuf::Message::~Message()':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/message.h:189: undefined reference to `vtable for google::protobuf::Message'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o): In function `axis::system::test::TestData const* google::protobuf::internal::DynamicCastToGenerated<axis::system::test::TestData const>(google::protobuf::Message const*)':
/home/toto/.conan/data/protobuf/3.5.1/axis/stable/package/13856a74412f9b4d58ac9612c055a0cf19317385/include/google/protobuf/generated_message_reflection.h:698: undefined reference to `typeinfo for google::protobuf::Message'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTVN4axis6system4test8TestDataE[_ZTVN4axis6system4test8TestDataE]+0x20): undefined reference to `google::protobuf::Message::GetTypeName[abi:cxx11]() const'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTVN4axis6system4test8TestDataE[_ZTVN4axis6system4test8TestDataE]+0x58): undefined reference to `google::protobuf::Message::InitializationErrorString[abi:cxx11]() const'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTVN4axis6system4test8TestDataE[_ZTVN4axis6system4test8TestDataE]+0x60): undefined reference to `google::protobuf::Message::CheckTypeAndMergeFrom(google::protobuf::MessageLite const&)'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTVN4axis6system4test8TestDataE[_ZTVN4axis6system4test8TestDataE]+0x80): undefined reference to `google::protobuf::MessageLite::SerializeWithCachedSizesToArray(unsigned char*) const'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTVN4axis6system4test8TestDataE[_ZTVN4axis6system4test8TestDataE]+0xb0): undefined reference to `google::protobuf::Message::DiscardUnknownFields()'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTVN4axis6system4test8TestDataE[_ZTVN4axis6system4test8TestDataE]+0xb8): undefined reference to `google::protobuf::Message::SpaceUsedLong() const'
/home/toto/.conan/data/system-definitions/0.0/axis/stable/package/9755f981ac44041fa0948f05e49abfa3d3346131/lib/libsystem-definitions.a(test.pb.cc.o):(.rodata._ZTIN4axis6system4test8TestDataE[_ZTIN4axis6system4test8TestDataE]+0x10): undefined reference to `typeinfo for google::protobuf::Message'



Edward Clark

unread,
Mar 22, 2018, 3:31:07 PM3/22/18
to Protocol Buffers
Perhaps look at the link command and see if it includes the protobuf libraries as you expect, or post it here.

doron atuar

unread,
Feb 17, 2019, 6:31:49 AM2/17/19
to Protocol Buffers
Hey, 
I'm struggling with a similar problem.
were you able to solve it?

Mayron Reis

unread,
Apr 13, 2020, 12:04:07 PM4/13/20
to Protocol Buffers

has anyone found any solution to this problem?
Reply all
Reply to author
Forward
0 new messages