Protobuf cannot be linked to ubuntu

I'm trying to use protobuf but for some reason the link doesn't work (just a snippet here):

Linking CXX executable app
CMakeFiles/app.dir/msg.pb.cc.o: In function `evoswarm::protobuf_AssignDesc_a_5fto_5fb_2eproto()':
msg.pb.cc:(.text+0x133): undefined reference to `google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(google::protobuf::Descriptor const*, google::protobuf::Message const*, int const*, int, int, int, int, int, int)'
msg.pb.cc:(.text+0x190): undefined reference to `google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(google::protobuf::Descriptor const*, google::protobuf::Message const*, int const*, int, int, int, int, int, int)'

      

Cmake finds the shared protobuf object file and uses it when linking:

/usr/bin/c++    -std=c++11     CMakeFiles/app.dir/main.cpp.o  CMakeFiles/app.dir/msg.pb.cc.o  -o app -rdynamic -lprotobuf -lpthread

      

and here is a small version of my CMakeLists.txt

cmake_minimum_required (VERSION 2.8)
project(app)

# build ProtoBufs
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/messages/*.proto")
PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
include_directories(${CMAKE_CURRENT_BINARY_DIR}) # that where the generated stuff ends

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")

#Files for main binary
set(SRC main.cpp)

add_executable (app  ${SRC} ${ProtoSources} ${ProtoHeaders})
TARGET_LINK_LIBRARIES (app ${PROTOBUF_LIBRARIES})

      

I first installed the library via source (didn't work either), uninstalled it again and installed the ubuntu package libprobofuv-dev and the protobuf compiler. The dpkg -L libprotobuf-dev output file is located here:

> sudo dpkg -L libprotobuf-dev
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/protobuf-lite.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/protobuf.pc
/usr/lib/x86_64-linux-gnu/libprotobuf-lite.a
/usr/lib/x86_64-linux-gnu/libprotobuf.a
/usr/include
/usr/include/google
/usr/include/google/protobuf
/usr/include/google/protobuf/dynamic_message.h
/usr/include/google/protobuf/generated_enum_reflection.h
/usr/include/google/protobuf/generated_message_reflection.h
/usr/include/google/protobuf/wire_format.h
/usr/include/google/protobuf/service.h
/usr/include/google/protobuf/io
/usr/include/google/protobuf/io/printer.h
/usr/include/google/protobuf/io/coded_stream.h
/usr/include/google/protobuf/io/tokenizer.h
/usr/include/google/protobuf/io/zero_copy_stream_impl_lite.h
/usr/include/google/protobuf/io/zero_copy_stream.h
/usr/include/google/protobuf/io/gzip_stream.h
/usr/include/google/protobuf/io/zero_copy_stream_impl.h
/usr/include/google/protobuf/reflection_ops.h
/usr/include/google/protobuf/extension_set.h
/usr/include/google/protobuf/descriptor.h
/usr/include/google/protobuf/generated_message_util.h
/usr/include/google/protobuf/wire_format_lite_inl.h
/usr/include/google/protobuf/stubs
/usr/include/google/protobuf/stubs/atomicops_internals_pnacl.h
/usr/include/google/protobuf/stubs/type_traits.h
/usr/include/google/protobuf/stubs/atomicops_internals_x86_msvc.h
/usr/include/google/protobuf/stubs/atomicops_internals_arm_gcc.h
/usr/include/google/protobuf/stubs/platform_macros.h
/usr/include/google/protobuf/stubs/once.h
/usr/include/google/protobuf/stubs/atomicops_internals_x86_gcc.h
/usr/include/google/protobuf/stubs/atomicops.h
/usr/include/google/protobuf/stubs/atomicops_internals_generic_gcc.h
/usr/include/google/protobuf/stubs/atomicops_internals_atomicword_compat.h
/usr/include/google/protobuf/stubs/common.h
/usr/include/google/protobuf/stubs/atomicops_internals_arm_qnx.h
/usr/include/google/protobuf/stubs/atomicops_internals_mips_gcc.h
/usr/include/google/protobuf/stubs/template_util.h
/usr/include/google/protobuf/stubs/atomicops_internals_macosx.h
/usr/include/google/protobuf/message_lite.h
/usr/include/google/protobuf/text_format.h
/usr/include/google/protobuf/descriptor_database.h
/usr/include/google/protobuf/descriptor.proto
/usr/include/google/protobuf/message.h
/usr/include/google/protobuf/repeated_field.h
/usr/include/google/protobuf/wire_format_lite.h
/usr/include/google/protobuf/unknown_field_set.h
/usr/include/google/protobuf/descriptor.pb.h
/usr/share
/usr/share/doc
/usr/lib/x86_64-linux-gnu/libprotobuf-lite.so
/usr/lib/x86_64-linux-gnu/libprotobuf.so
/usr/share/doc/libprotobuf-dev

      

+3


source to share


1 answer


As @frymode emphasizes in his comment, the reference to NewGeneratedMessageReflection means that the compiler has generated code that uses Protobuf version 3 (since I used that version in my .proto files). However, the library files installed from the ubuntu package pulled version 2 into my system, so no methods could be found.



The solution was to drop everything again and build the protobuf including the protoc from source.

+2


source







All Articles