问题
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
)
And the error message I get is:
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
Any help would be appreciated.
Update:
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
)
回答1:
The name of the source files generated by protobuf_generate_cpp()
ends up in PROTO_SRCS
.
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})
...should probably not have VisionData.cc
in it.
来源:https://stackoverflow.com/questions/32647517/protocol-buffer-with-cmakelists