CMAKE警告:ROS 2中未使用手动指定的变量
这个问题可能是ROS 2的特定于ROS 2。我定义了一个自定义标志,例如 Hello_ros
。汇编后,cmake发出以下警告:
$ colcon build --allow-overriding examples_rclcpp_minimal_composition --cmake-args -DHELLO_ROS=OFF
Starting >>> realsense2_camera_msgs
Starting >>> examples_rclcpp_minimal_composition
--- stderr: realsense2_camera_msgs
CMake Warning:
Manually-specified variables were not used by the project:
HELLO_ROS
---
Finished <<< realsense2_camera_msgs [4.43s]
Starting >>> realsense2_camera
Starting >>> realsense2_description
--- stderr: realsense2_description
CMake Warning:
Manually-specified variables were not used by the project:
HELLO_ROS
---
Finished <<< realsense2_description [0.69s]
Finished <<< examples_rclcpp_minimal_composition [8.01s]
--- stderr: realsense2_camera
CMake Warning:
Manually-specified variables were not used by the project:
HELLO_ROS
---
Finished <<< realsense2_camera [15.5s]
Summary: 4 packages finished [20.1s]
3 packages had stderr output: realsense2_camera realsense2_camera_msgs realsense2_description
以下是我工作空间中的软件包:
.
├── minimal_composition
└── realsense-ros
这些软件包取自 minimal_composition 和。如下所示,在publisher_node.cpp:
void PublisherNode::on_timer() {
auto message = std_msgs::msg::String();
#ifdef HELLO_ROS
message.data = "ON! " + std::to_string(count_++);
#else
message.data = "OFF! " + std::to_string(count_++);
#endif
RCLCPP_INFO(this->get_logger(), "Publisher: '%s'", message.data.c_str());
publisher_->publish(message);
}
Similarly, cmakelists.txt 被修改如下所示:
add_library(composition_nodes SHARED
src/publisher_node.cpp
src/subscriber_node.cpp)
option(HELLO_ROS "Use HELLO_ROS" OFF) # OFF by default
if( HELLO_ROS )
target_compile_definitions(composition_nodes
PRIVATE "MINIMAL_COMPOSITION_DLL"
PRIVATE HELLO_ROS
)
else()
target_compile_definitions(composition_nodes
PRIVATE "MINIMAL_COMPOSITION_DLL"
)
endif(HELLO_ROS)
ament_target_dependencies(composition_nodes rclcpp rclcpp_components std_msgs)
问题
如何摆脱此警告?
版本信息
名称 | 版本 |
---|---|
cmake | 3.16.3 |
GCC | 9.4.0 |
Ros | Foxy |
Ubuntu | 20.04.4 LTS |
更新,
因此以下是到目前为止的分析:
- 我删除了
#else
从#ifdef hello_ros
并在CPP文件上添加了#if Hello_ros #else #endif
,如下所示:std :: string msg = std :: to_string(count _ ++); #如果Hello_ros msg +=“ hello_ros在!”; #别的 msg +=“ hello_ros不关闭!”; #endif #ifdef hello_ros msg +=“ hello_ros已定义!”; #endif message.data = msg;
- 我从
cmakelists.txt
中删除了,以将其转换为以下方式:
target_compile_definitions(composition_nodes private“ minimal_composition_dll” private“ hello_ros = $ {hello_ros}”)
- 这次我仅选择了我的软件包,然后用
-cmake-args -dhello_ros = on
参数编制了整个工作空间。
观察结果:
- 即使该项目也使用
-dhello_ros = on
编译,#if Hello_ros ***
被编译为###否则
。 - 不过,我可以看到
#ifdef
已启用。 - 此外,我可以看到
hello_ros
设置为内部cmakelists.txt上,如下所示:./构建/示例_rclcpp_minimal_composition/cmakefiles/composition_nodes.dir/disterinfo.cmake.cmake:15:“ hello_ros = on” ./build/examples_rclcpp_minimal_composition/cmakecache.txt:250://use hello_ros ./build/examples_rclcpp_minimal_composition/cmakecache.txt:251:hello_ros:bool:bool = on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论