My goal is to configure cmake file and build my app with protobuf lib.
My attempted steps:
- built protobuf in Ubuntu 20.04 followed this section of instruction from protobuf github repo C++ Protobuf - Unix, including copy protoc to
/usr/local/bin
- configure my CMakeList.txt as below:
include(FindProtobuf)
find_package(Protobuf REQUIRED)
message("${Protobuf_LIBRARIES}")
message("${Protobuf_INCLUDE_DIRS}")
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS XXX.proto XXX.proto)
message("${PROTO_SRCS}")
message("${PROTO_HDRS}")
add_library(proto_msg_lib ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(proto_msg_lib INTERFACE ${Protobuf_LIBRARIES})
when I ran cmake, besides a long list of errors indicating it can not find a bunch of "include files" related to internal protobuf lib. I also saw this warning which bother me a lot:
Protobuf compiler version 21.12 doesn't match library version
The printout for Protobuf_LIBRARIES and Protobuf_INCLUDE_DIRS are
/usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread
/usr/include
My questions are:
- why would
find_package(Protobuf REQUIRED)
look for protobuf lib in this path/usr/lib/x86_64-linux-gnu/libprotobuf.so
? - How can I find this libprotobuf.so for the correct version of protobuf I built(v21.12)?
- Do I need to include all the source file header from protobuf , or I can just include a libprotobuf.so (or similar thing)?