我在使用c++测试protobuf官方的示例代码时,有个报错一直没办法解决。困扰了我好几天,百度google均没找到解决办法。特来求助大神
CMakeLists.txt文件内容:
[C++] 纯文本查看 复制代码 cmake_minimum_required(VERSION 3.22)
project(untitled4)
message(STATUS "测试!!!!!!!!!!!!!!!!!!!!")
# Find required protobuf package
find_package(Protobuf REQUIRED)
if (PROTOBUF_FOUND)
message(STATUS "protobuf library found")
else ()
message(FATAL_ERROR "protobuf library is needed but cant be found")
endif ()
message(STATUS "protobuf include dir: ${PROTOBUF_INCLUDE_DIRS}")
set(CMAKE_CXX_STANDARD 23)
#CXXFLAGS="$(pkg-config --cflags protobuf)"
#LIBS="$(pkg-config --libs protobuf)"
#`pkg-config --cflags --libs protobuf`
set(CMAKE_CXX_FLAGS "`pkg-config --cflags --libs protobuf`")
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS addressbook.proto)
message(SATUS ${PROTO_SRCS} ${PROTO_HDRS})
add_executable(untitled4 main.cpp ${PROTO_SRCS} ${PROTO_HDRS})
target_include_directories(untitled4
PUBLIC
${PROTOBUF_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
)
# link the exe against the libraries
target_link_libraries(untitled4
${PROTOBUF_LIBRARIES}
)
报错截图:
环境:
完整的项目地址:
https://github.com/weiweirj/clion_protobuf_test
|