带有CMakeLists的协议缓冲区 [英] Protocol Buffer with CMakeLists
问题描述
我有一个项目,该项目的父指令下有 src
, include
和一些较旧的文件夹。我创建了一个名为 proto
的文件夹,其中包含我的 VisionData.proto
。我想生成预期的输出文件,但是不起作用。我查看了 it 的官方网站,并做了什么他们在那里写信,但仍然没有运气。这是我的CMakeLists:
I have a project which has src
, include
and some older folders under its parent dictory. I created a folder called proto
, which has my VisionData.proto
in it. I want to generate the expected output files, however it doesn't work. I looked at the official site of it and did whatever they wrote there, but still no luck. Here is my CMakeLists:
cmake_minimum_required(VERSION 2.8.3)
project(uwsim_imgproc)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set_source_files_properties(${PROTO_SRC} ${PROTO_HEADER} PROPERTIES GENERATED TRUE)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
roscpp
sensor_msgs
std_msgs
image_transport
)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
catkin_package(
INCLUDE_DIRS include
LIBRARIES uwsim_imgproc filters
CATKIN_DEPENDS cv_bridge roscpp sensor_msgs std_msgs
# DEPENDS system_lib
)
set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS} PARENT_SCOPE)
set(PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES} PARENT_SCOPE)
set(PROTO_SRC ${PROTO_SRC} PARENT_SCOPE)
set(PROTO_HEADER ${PROTO_HEADER} PARENT_SCOPE)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS VisionData.proto)
include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
include
)
link_directories(
${OpenCV_LINK_DIRS}
)
add_library(filters
src/Obstacle.cpp
src/HorizonDetector.cpp
src/GenericTools.cpp
src/Kalman.cpp
src/HungarianAlg.cpp
src/Ctracker.cpp
)
add_executable(cameraSubscriber src/main.cpp)
add_executable(VisionData VisionData.cc ${PROTO_SRCS} ${PROTO_HDRS})
add_dependencies(cameraSubscriber ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(VisionData
${PROTOBUF_LIBRARIES}
)
target_link_libraries(filters
${OpenCV_LIBRARIES}
)
target_link_libraries(cameraSubscriber
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
filters
)
我得到的错误消息是:
CMake Error at uwsim_imgproc/CMakeLists.txt:60 (add_executable):
Cannot find source file:
VisionData.cc
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
任何会得到帮助。
更新:
解决了错误问题但是,我的CMakeLists不会生成应已生成的任何.h或.cc文件。
Fixed the issue with the error, however, my CMakeLists does not generate any .h or .cc file which should have been generated.
cmake_minimum_required(VERSION 2.8.3)
project(uwsim_imgproc)
include(FindProtobuf)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set_source_files_properties(${PROTO_SRC} ${PROTO_HEADER} PROPERTIES GENERATED TRUE)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
roscpp
sensor_msgs
std_msgs
image_transport
)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
catkin_package(
INCLUDE_DIRS include
LIBRARIES uwsim_imgproc filters
CATKIN_DEPENDS cv_bridge roscpp sensor_msgs std_msgs
# DEPENDS system_lib
)
set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS} PARENT_SCOPE)
set(PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES} PARENT_SCOPE)
set(PROTO_SRC ${PROTO_SRC} PARENT_SCOPE)
set(PROTO_HEADER ${PROTO_HEADER} PARENT_SCOPE)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS proto/VisionData.proto)
include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
include
)
link_directories(
${OpenCV_LINK_DIRS}
)
add_library(filters
src/Obstacle.cpp
src/HorizonDetector.cpp
src/GenericTools.cpp
src/Kalman.cpp
src/HungarianAlg.cpp
src/Ctracker.cpp
)
add_executable(cameraSubscriber src/main.cpp ${PROTO_SRCS} ${PROTO_HDRS})
add_dependencies(cameraSubscriber ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(cameraSubscriber
${PROTOBUF_LIBRARIES}
)
target_link_libraries(filters
${OpenCV_LIBRARIES}
)
target_link_libraries(cameraSubscriber
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
filters
)
推荐答案
<$ c $生成的源文件的名称c> protobuf_generate_cpp()最终以 PROTO_SRCS
结尾。
-
此文件可能会在
CMAKE_BINARY_DIR
中生成(因为i t的CMake策略不在源目录中生成文件。)
This file will likely be generated in
CMAKE_BINARY_DIR
(since it's CMake policy not to generate files in the source directory).
此文件可能遵循一些您不必了解的内部命名方案。
This file probably follows some internal naming scheme you don't have to know about.
所以您的电话线...
So your line...
add_executable(VisionData VisionData.cc ${PROTO_SRCS} ${PROTO_HDRS})
。 ..应该没有 VisionData.cc
。
这篇关于带有CMakeLists的协议缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!