gpt4 book ai didi

c++ - ROS C++ catkin 找不到我的自定义消息

转载 作者:行者123 更新时间:2023-11-30 03:39:35 25 4
gpt4 key购买 nike

编译器提示未找到消息 (.../message.h)。请参阅下面我的 CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(my_package)
add_compile_options(-std=c++11)


find_package(catkin REQUIRED
COMPONENTS cv_bridge
image_transport
roscpp
#rospy
sensor_msgs
std_msgs
message_generation
genmsg
external_package
)
find_package(nodelet REQUIRED)


#----
add_message_files( FILES
my_message1.msg
my_message2.msg

)

generate_messages( DEPENDENCIES
std_msgs sensor_msgs
)

catkin_package(
CATKIN_DEPENDS message_runtime std_msgs sensor_msgs roscpp cv_bridge image_transport
)



#****** EXTRA PACKAGES
find_package(LAPACK REQUIRED)
find_package(BLAS REQUIRED)
find_package( PkgConfig REQUIRED)
FIND_PACKAGE(Boost)
find_package( OpenCV )
include_directories(${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} )

SET(MY_FLAG ok) # OR no!!

if(MY_FLAG)
#**** exe files
set(exefiles
file1
file2
)

foreach(file ${exefiles})
add_executable(${file} ${CMAKE_CURRENT_SOURCE_DIR}/pathToExeFiles/${file}.cpp )
endforeach(file)


#****** Lib & link
include_directories(${SRC}/pathToMyLib)
set(MY_LIB
lib1
lib2
libn
)
endif(MY_FLAG)

foreach(file ${exefiles})
target_link_libraries(${file2link}
${MY_LIB}
${MY_LIB}
${MY_LIB}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${gsl_LIBRARIES} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}
${OpenCV_LIBRARIES}
)

add_dependencies(${file} external_package_generate_messages_cpp ${${my_package}_EXPORTED_TARGETS})
endforeach(file)


ADD_SUBDIRECTORY(src)

但是,我可以使用以下技巧进行编译。我首先将 My_FLAG 设置为 flase 并编译。接下来,我将其设置回 true 并再次编译。通过这样做它工作正常。但是......我猜应该有一个更优雅/专业/直接的解决方案。到目前为止,我无法检测到此问题的原因。请问有什么解决办法吗?

我认为这个问题与依赖关系的顺序有关……哪个?不知道...

最佳答案

看起来您的 EXPORTED_TARGETS 依赖项是错误的。

add_dependencies(${file} external_package_generate_messages_cpp  ${${my_package}_EXPORTED_TARGETS})

${${my_package}_EXPORTED_TARGETS} 应该是 ${${PROJECT_NAME}_EXPORTED_TARGETS}${my_package_EXPORTED_TARGETS}/p>

所以:

add_dependencies(${file} external_package_generate_messages_cpp  ${${PROJECT_NAME}_EXPORTED_TARGETS})

如果依赖 ${catkin_EXPORTED_TARGETS} 可能会有所帮助。

关于c++ - ROS C++ catkin 找不到我的自定义消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38735689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com