CMAKE警告:ROS 2中未使用手动指定的变量

发布于 2025-02-10 04:50:47 字数 4457 浏览 2 评论 0 原文

这个问题可能是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

更新,

因此以下是到目前为止的分析:

  1. 我删除了 #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;
     
  2. 我从 cmakelists.txt 中删除了,以将其转换为以下方式:
      target_compile_definitions(composition_nodes private“ minimal_composition_dll” private“ hello_ros = $ {hello_ros}”)
     
  3. 这次我仅选择了我的软件包,然后用 -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
     

This issue could be specific to ROS 2. I have defined a custom flag, say HELLO_ROS. Upon compilation, CMake throws the following warning:

$ 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

Following are the packages in my workspace:

.
├── minimal_composition
└── realsense-ros

These packages are taken from minimal_composition and realsense-ros. A minor modification as shown below is done in 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 is modified as shown below:

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)

Question

How to get rid of this warning?

Version Info

Name Version
CMake 3.16.3
GCC 9.4.0
ROS Foxy
Ubuntu 20.04.4 LTS

Update

So here is the analysis so far:

  1. I removed #else from #ifdef HELLO_ROS and added #if HELLO_ROS #else #endif on the CPP file as shown below:
      std::string msg = std::to_string(count_++);
    
    #if HELLO_ROS
      msg += " HELLO_ROS is ON! ";
    #else
      msg += " HELLO_ROS is OFF! ";
    #endif
    
    #ifdef HELLO_ROS
      msg += " HELLO_ROS is DEFINED! ";
    #endif
      message.data = msg;
    
  2. I removed if/else from CMakeLists.txt to convert it to the following way:
    target_compile_definitions(composition_nodes  PRIVATE "MINIMAL_COMPOSITION_DLL"  PRIVATE "HELLO_ROS=${HELLO_ROS}")
    
  3. I selected only my package this time and compiled the whole workspace with the --cmake-args -DHELLO_ROS=ON argument.

Observations:

  • Even though, the project was compiled with -DHELLO_ROS=ON, the #if HELLO_ROS *** got compiled to #else.
  • Though, I can see that #ifdef is enabled.
  • Furthermore, I can see that HELLO_ROS is set to ON inside CMakeLists.txt such as shown below:
    ./build/examples_rclcpp_minimal_composition/CMakeFiles/composition_nodes.dir/DependInfo.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=ON
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文