为什么 CMake 不编译这个 protobuff class?
Why won't CMake compile this protobuff class?
因此,我尝试按照有关如何使用 Gazebo 的订阅服务添加主题的示例进行操作。 las,其中一个步骤是创建一个 protobuf 对象,不幸的是,当我 运行 CMake 时,我的 protobuff class 将无法编译。这是我目前所拥有的:
import "vector3d.proto";
message ModelVelResponse
{
required AVelV angularVel = 1;
required LVelV linearVel = 2;
}
message AVelV{
repeated gazebo.msgs.Vector3d angularVel = 1;
}
message LVelV{
repeated gazebo.msgs.Vector3d linearVel = 1;
}
这是我的 cmake 文件
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(Protobuf REQUIRED)
set(PROTOBUF_IMPORT_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
endif()
endforeach()
set (msgs
velocity_message.proto
${PROTOBUF_IMPORT_DIRS}/vector3d.proto
${PROTOBUF_IMPORT_DIRS}/header.proto
${PROTOBUF_IMPORT_DIRS}/time.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(velocity_msgs SHARED ${PROTO_SRCS})
target_link_libraries(velocity_msgs ${PROTOBUF_LIBRARY})
find_package(Boost REQUIRED COMPONENTS system)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include (FindPkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(GAZEBO gazebo)
endif()
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
add_library(model_vel SHARED model_vel.cc)
target_link_libraries(model_vel ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES})
知道我做错了什么吗?我的 protobuf 文件位于 "msgs" 子目录中,但是当我将应该生成 protobuf 库的代码移动到子目录中时,它仍然无法编译。它也没有解决任何错误。
更新:我的代码基于 this 教程。
我通过将 make 文件更改为这样解决了这个问题:
find_package(Protobuf REQUIRED)
set(PROTOBUF_IMPORT_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
endif()
endforeach()
set (msgs
velocity_message.proto
${PROTOBUF_IMPORT_DIRS}/vector3d.proto
${PROTOBUF_IMPORT_DIRS}/header.proto
${PROTOBUF_IMPORT_DIRS}/time.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(velocity_msgs SHARED ${PROTO_SRCS})
target_link_libraries(velocity_msgs ${PROTOBUF_LIBRARY})
我只需要将它添加为共享库。
因此,我尝试按照有关如何使用 Gazebo 的订阅服务添加主题的示例进行操作。 las,其中一个步骤是创建一个 protobuf 对象,不幸的是,当我 运行 CMake 时,我的 protobuff class 将无法编译。这是我目前所拥有的:
import "vector3d.proto";
message ModelVelResponse
{
required AVelV angularVel = 1;
required LVelV linearVel = 2;
}
message AVelV{
repeated gazebo.msgs.Vector3d angularVel = 1;
}
message LVelV{
repeated gazebo.msgs.Vector3d linearVel = 1;
}
这是我的 cmake 文件
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(Protobuf REQUIRED)
set(PROTOBUF_IMPORT_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
endif()
endforeach()
set (msgs
velocity_message.proto
${PROTOBUF_IMPORT_DIRS}/vector3d.proto
${PROTOBUF_IMPORT_DIRS}/header.proto
${PROTOBUF_IMPORT_DIRS}/time.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(velocity_msgs SHARED ${PROTO_SRCS})
target_link_libraries(velocity_msgs ${PROTOBUF_LIBRARY})
find_package(Boost REQUIRED COMPONENTS system)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
include (FindPkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(GAZEBO gazebo)
endif()
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
add_library(model_vel SHARED model_vel.cc)
target_link_libraries(model_vel ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES})
知道我做错了什么吗?我的 protobuf 文件位于 "msgs" 子目录中,但是当我将应该生成 protobuf 库的代码移动到子目录中时,它仍然无法编译。它也没有解决任何错误。
更新:我的代码基于 this 教程。
我通过将 make 文件更改为这样解决了这个问题:
find_package(Protobuf REQUIRED)
set(PROTOBUF_IMPORT_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
endif()
endforeach()
set (msgs
velocity_message.proto
${PROTOBUF_IMPORT_DIRS}/vector3d.proto
${PROTOBUF_IMPORT_DIRS}/header.proto
${PROTOBUF_IMPORT_DIRS}/time.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(velocity_msgs SHARED ${PROTO_SRCS})
target_link_libraries(velocity_msgs ${PROTOBUF_LIBRARY})
我只需要将它添加为共享库。