一. msg文件
文件地址:src平级的目录下放msg文件夹,里面放proto文件
文件内容:.proto文件如下所示:
syntax = "proto3";
package hh.ad.messages;
option optimize_for = LITE_RUNTIME;
message Flag{
double timestamp = 1;
uint32 flag = 2;
uint32 id = 3;
string name = 4;
double lat = 5;
double lon = 6;
float heading = 7;
string publisher_id = 536870909; // uuid of the publisher
uint64 counter = 536870910; // message counter
uint64 publish_ts = 536870911; // publish utc timestamp; unit : microsecond(us)
}
二. cmakelists
将msg编译成.cc和.h
set(PROTO_DIR "${CMAKE_CURRENT_LIST_DIR}/msg")
set(PROTO_SRCS ${PROTO_DIR}/*.pb.cc)
execute_process(COMMAND sh -c "protoc -I=${PROTO_DIR} --cpp_out=${PROTO_DIR} ${PROTO_DIR}/*.proto")
用execute_process编译出来的proto的cc和h文件也会在msg文件夹下
不要用protobuf_generate_cpp
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTOFILES})
protobuf_generate_cpp编译出来的.h和.cc在build中,后面链接不是很好链接,不建议使用
PROTO_SRCS中的所有路径完整写入proto_SRC变量中
file(GLOB proto_SRC ${PROTO_SRCS})
编译可执行文件加入proto
add_executable(pointcloud_load src/pointcloud_load.cpp ${proto_SRC})
注意:
set和file的区别
set(test ${PROTO_SRCS})
file(GLOB proto_SRC ${PROTO_SRCS})
结果如下:
======test: /home/hh/WorkSpace/catkin_hpa/src/hpa_lidar_tool/msg/*.pb.cc
======proto_SRC: /home/hh/WorkSpace/catkin_hpa/src/hpa_lidar_tool/msg/orin_mapping_flag.pb.cc;/home/hh/WorkSpace/catkin_hpa/src/hpa_lidar_tool/msg/orin_match_pose.pb.cc