proto在ubuntu18 vscode c++中如何使用cmake链接
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto)
protobuf_generate_python(PROTO_PY foo.proto)
add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(bar ${Protobuf_LIBRARIES})
上面为参考的完整版,https://www.cnblogs.com/bigoldpan/p/14502873.html
我个人试了一下,这是我个人的:
cmake_minimum_required (VERSION 2.8)
PROJECT (PBTEST)
SET(SRC_LIST src/write_test.cpp)
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
#include_directories(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(pbtest ${SRC_LIST} src/test.pb.h src/test.pb.cc)
target_link_libraries(pbtest ${Protobuf_LIBRARIES})
proto在写入文件时是二进制的,人类不可读,这也是它速度快的原因,然后再写个读的程序就可以显示人类可读的内容了。