[ROS2 Windows] Running C++ Node By Direct DLL/Lib Reference
Hello,
My Setup:
- ROS 2 Eloquent Elusor
- Installed pre-built release binaries (ros2-eloquent-20191122-windows-release-amd64.zip)
- Windows 10
- Visual Studio 2019
Problem Description
For my use case I would like to run a ros2 Windows node in another application that cannot be built with Colcon (it is a large project built with another build system). As a starter I am trying to complete the setup in a simple C++ console app in Visual Studio by directly referencing the ros2 library files and headers without using colcon build process. In Visual Studio I have referenced the ROS 2 headers and static library files as well as put the DLLs in my bin folder. I also source setup.bat prior to running the console app (call C:\dev\ros2_eloquent\local_setup.bat
). I am able to run the demo nodes that come with ros 2 without issue (those build from colcon and using ros2 run <package> <node>
).
The init call seems to go through without error but ROS2 crashes when trying to make a node (auto node = rclcpp::Node::make_shared("minimal_publisher")
) with an
InvalidNodeNameError exception:
Unhandled exception at 0x00007FF85B97A839 in RosExpRelease.exe: Microsoft C++ exception: rclcpp::exceptions::InvalidNodeNameError at memory location 0x0000009F500FCB10
Is it possible to develop a ROS2 node using only references to the library and header files without the colcon build process?
Any help you could give would be appreciated. Thank you.
Visual Studio Configuration
- C/C++ > Additional Include Directories = C:\dev\ros2_eloquent\include
- Linker > Additional Library Directories = C:\dev\ros2_eloquent\Lib
- Linker > Input > Additional Dependencies = all .lib files in C:\dev\ros2_eloquent\Lib
- Copied all .dll files to bin output
- I also call C:\dev\ros2_eloquent\local_setup.bat prior to running
Exception
Unhandled exception at 0x00007FFB9391A839 in RosExpRelease.exe: Microsoft C++ exception: rclcpp::exceptions::InvalidNodeNameError at memory location 0x0000009FD86FCC30.
Stack Trace
KernelBase.dll!00007ffb9391a839()
vcruntime140.dll!00007ffb52654890()
rclcpp.dll!00007ffb23da4176()
rclcpp.dll!00007ffb23d9c0e0()
rclcpp.dll!00007ffb23d9cd14()
RosExpRelease.exe!std::_Construct_in_place<rclcpp::Node,char const (&)[18]>(rclcpp::Node & _Obj, const char[18] & <_Args_0>) Line 202
at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\xmemory(202)
RosExpRelease.exe!std::_Ref_count_obj2<rclcpp::Node>::_Ref_count_obj2<rclcpp::Node><char const (&)[18]>(const char[18] & <_Args_0>) Line 1491
at C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\memory(1491)
RosExpRelease.exe!std::make_shared<rclcpp::Node,char const (&)[18]>(const char[18] & <_Args_0>) Line 1591
at C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\memory(1591)
RosExpRelease.exe!rclcpp::Node::make_shared<char const (&)[18]>(const char[18] & <args_0>) Line 75
at C:\dev\ros2_eloquent\include\rclcpp\node.hpp(75)
RosExpRelease.exe!main(int argc, char * * argv) Line 9
at C:\Users\name\source\repos\RosExpRelease\RosExpRelease\RosExpRelease.cpp(9)
[External Code]
Pictures
I do not have enough karma to post pictures on the forums currently but I've attached a link to a google ...
both of these are text. So clease copy them verbatim into your question text. There should be no need for screenshots for these.
Hi,
Thank you for getting back to me. I had listed the exception text in my original post but I edited it to make it clearer.
The stack trace was:
I am also facing same issue. ROS2 crashes when trying to make a node (auto node = rclcpp::Node::make_shared("minimal_publisher")
Have you been able to fix this issue? I have a lot of LNK2019 errors even though a have the same setup as you :b
Were you able to fix this issue?
Hey all! I've managed to get it to work - two things that are worth noting: 1. You need to call rclcpp::init() and 2.You need to either build ros2 manually to be able to debug into it or run everything in release mode (https://github.com/ms-iot/ROSOnWindow...)
If you have any other questions/ issues feel free to message me! I might create a "tutorial" somewhere and link it, if you have recommendations on where/how to do that I'd appreciate it.
I am having a similar use case where i need to wrap ROS functions into a DLL and call it from another application. I was able to build the dll but it crashes when called.
Hi, How do you call the functions in the wrapper.cpp in a program to publish to a topic?