This error is not easy to replicate since I am working with ROS 2 on Windows and the installation is not that simple but I think it is a Visual Studio issue so maybe you guys have a clue whats going on here.
I want to use ROS 2 in a Visual Studio 2019 project. To do this I did the following things:
- C/C++ > Additional Include Directories = C:\dev\ros2_foxy\include
- Linker > Additional Library Directories = C:\dev\ros2_foxy\Lib
- Linker > Input > Additional Dependencies = all .lib files in
- C:\dev\ros2_foxy\Lib Copied all .dll files to bin output
And I added the path C:/ros2_foxy/install/bin to my environment path.
Calling the ROS init function works fine so the connection to ROS should be fine. In ROS you use nodes to communicate. Your own nodes are classes which inherit from a "Node" parent class and are initialized with a node name (here "pub") like this:
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher(): Node("pub"){}
}
In the node.cpp of ROS the node class is defined like this:
Node::Node(
const std::string & node_name,
const NodeOptions & options)
: Node(node_name, "", options)
{
}
When I debug through the code node_name does not contain "pub" but a few random characters (they change every time), then "p" "u" "b" and "\0".
Because of this I get a "invalid node name" error. I tried to find out where exactly the random characters get added but to be honest I haven´t been able to find any earlier reference to node_name than this.
I'd be glad about any idea where the issue might be.
Edit: The definition of the node class is not that simple since it comes from ROS. All of this works fine when built with colcon and the command line, the issues only arise when using Visual Studio to build & run the code. But if you are interested you can find the documentation here and the implementation here.
My test code is from the "writing a publisher" example tutorial.