Reputation: 77
My goal is to configure cmake file and build my app with protobuf lib.
My attempted steps:
/usr/local/bin
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:
find_package(Protobuf REQUIRED)
look for protobuf lib in this path /usr/lib/x86_64-linux-gnu/libprotobuf.so
?Upvotes: 2
Views: 2084
Reputation: 9329
Did you try to use Protobuf_ROOT
to specify your local protobuf install ?
ref: https://cmake.org/cmake/help/latest/variable/PackageName_ROOT.html
note: an other way would be to FetchContent()
protobuf in your build directly
message(CHECK_START "Fetching Protobuf")
list(APPEND CMAKE_MESSAGE_INDENT " ")
set(protobuf_BUILD_TESTS OFF)
set(protobuf_BUILD_SHARED_LIBS OFF)
set(protobuf_BUILD_EXPORT OFF)
set(protobuf_MSVC_STATIC_RUNTIME OFF)
FetchContent_Declare(
protobuf
GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
GIT_TAG "v21.12"
GIT_SUBMODULES ""
#PATCH_COMMAND git apply --ignore-whitespace ".../protobuf-v21.12.patch"
)
FetchContent_MakeAvailable(protobuf)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
note: Since 3.24, You can also use OVERRIDE_FIND_PACKAGE
ref: https://cmake.org/cmake/help/latest/module/FetchContent.html#command:fetchcontent_declare
Upvotes: 0