ros2 / ros2_documentation

ROS 2 docs repository
https://docs.ros.org/en/rolling
Creative Commons Attribution 4.0 International
535 stars 1.06k forks source link

Use VS2022 development project in windows, release project times error #4753

Closed zanxueyan closed 1 week ago

zanxueyan commented 1 week ago

The test code in windows is as follows:

`#include "rclcpp/rclcpp.hpp"

include "std_msgs/msg/string.hpp"

class NodeA : public rclcpp::Node { public: NodeA() : Node("nodea") { publisher = this->create_publisher("topicb", 10); timer = this->create_wall_timer( std::chrono::milliseconds(500), std::bind(&NodeA::publish_message, this)); }

private: void publish_message() { auto message = std_msgs::msg::String(); message.data = "Hello from Node A"; RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.cstr()); publisher->publish(message); }

rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;

};

class NodeB : public rclcpp::Node { public: NodeB() : Node("nodeb") { subscription = this->create_subscription( "topic_b", 10, std::bind(&NodeB::callback, this, std::placeholders::_1)); }

private: void callback(const std_msgs::msg::String::SharedPtr msg) { RCLCPP_INFO(this->get_logger(), "Received: '%s'", msg->data.c_str()); }

rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;

};

int main(int argc, char* argv[]) { rclcpp::init(argc, argv); rclcpp::executors::MultiThreadedExecutor executor; auto node_a = std::make_shared(); auto node_b = std::make_shared(); executor.add_node(node_a); executor.add_node(nodeb); executor.spin(); rclcpp::shutdown(); return 0; }` There is no error in Debug, and the following error in Release: Error content Unhandled exception at 0x00007FF95C0CFABC (located in ros2Demo.exe) : Microsoft C++ exception: RCLCPP: : exceptions: : RCLInvalidArgument, located in the memory location 0 x00000014a45ee250._

Please help me. What's wrong with me? How should the code be modified? Thank you for your help

clalancette commented 1 week ago

Please open questions like this on https://robotics.stackexchange.com/questions/tagged/ros, which is our central Question and Answer site. You'll get a better answer there, and it will be searchable for the future.

Make sure to include a lot of information on what platform you are using, which ROS distribution you are using, and the exact steps you took.