ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

[ROS2 Windows] Running C++ Node By Direct DLL/Lib Reference

asked 2019-12-18 10:04:40 -0500

stefan_ gravatar image

updated 2021-12-15 19:58:21 -0500

osilva gravatar image

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 ... (more)

edit retag flag offensive close merge delete

Comments

I do not have enough karma to post pictures on the forums currently but I've attached a link to a google drive hosting images for:

  • Exception message
  • Stack trace

both of these are text. So clease copy them verbatim into your question text. There should be no need for screenshots for these.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-18 13:48:33 -0500 )edit

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:

    KernelBase.dll!00007ffb9391a839()   Unknown
    vcruntime140.dll!00007ffb52654890() Unknown
    rclcpp.dll!00007ffb23da4176()   Unknown
    rclcpp.dll!00007ffb23d9c0e0()   Unknown
    rclcpp.dll!00007ffb23d9cd14()   Unknown
>   RosExpRelease.exe!std::_Construct_in_place<rclcpp::Node,char const (&)[18]>(rclcpp::Node & _Obj, const char[18] & <_Args_0>) Line 202   C++
    RosExpRelease.exe!std::_Ref_count_obj2<rclcpp::Node>::_Ref_count_obj2<rclcpp::Node><char const (&)[18]>(const char[18] & <_Args_0>) Line 1491   C++
    RosExpRelease.exe!std::make_shared<rclcpp::Node,char const (&)[18]>(const char[18] & <_Args_0>) Line 1591   C++
    RosExpRelease.exe!rclcpp::Node::make_shared<char const (&)[18]>(const char[18] & <args_0>) Line 75  C++
    RosExpRelease.exe!main(int argc, char * * argv) Line 9  C++
    [External Code]
stefan_ gravatar image stefan_  ( 2019-12-18 15:09:36 -0500 )edit

I am also facing same issue. ROS2 crashes when trying to make a node (auto node = rclcpp::Node::make_shared("minimal_publisher")

gururajvj7 gravatar image gururajvj7  ( 2020-04-21 04:54:13 -0500 )edit

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

TheBee gravatar image TheBee  ( 2021-01-29 03:54:08 -0500 )edit

Were you able to fix this issue?

Sid7117 gravatar image Sid7117  ( 2021-12-15 01:11:11 -0500 )edit

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.

TheBee gravatar image TheBee  ( 2021-12-15 02:45:38 -0500 )edit

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.

Sid7117 gravatar image Sid7117  ( 2021-12-16 00:03:53 -0500 )edit

Hi, How do you call the functions in the wrapper.cpp in a program to publish to a topic?

Sid7117 gravatar image Sid7117  ( 2021-12-16 07:54:36 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-12-15 02:51:13 -0500

TheBee gravatar image

updated 2021-12-30 08:11:46 -0500

Adding my comment as an answer so everyone gets notified:

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 (more info: 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.

Update: I've created a minimal solution on how to integrate ROS2 in Visual Studio 2019, build a DLL and call the DLL functions through C# in this repo: https://github.com/ItsMeTheBee/Visual...

The repo does not contain everything I've done but I think this "bare" example is better than a complex structure they likely don't need. Feel free to create issues - I'll try to help =)

edit flag offensive delete link more

Comments

Hi TheBee, could you provide an email where I can contact you?. I am trying to solve the same issue since 1 month ago, any help would be appreciated.

Thanks in advance for your response!

edgarmg gravatar image edgarmg  ( 2021-12-15 18:26:39 -0500 )edit

If the tutorial is concise enough you could document in you answer. This forum is top when it comes to ROS searches and you can get more karma :)

osilva gravatar image osilva  ( 2021-12-15 19:56:49 -0500 )edit

Added a couple tags to your question to help future search

osilva gravatar image osilva  ( 2021-12-15 19:58:53 -0500 )edit

@edgarmg Check out the GitHub repo and create issues there, that way others with the same issues can find the solution as well (plus private Emails tend to get lost in the spam folder, GitHub issues are a sure way for me to see it)

TheBee gravatar image TheBee  ( 2021-12-30 08:14:15 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2019-12-18 09:57:31 -0500

Seen: 1,262 times

Last updated: Dec 30 '21