0
$\begingroup$

Rosanswers logo

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 drive hosting images for:

  • Exception message
  • Stack trace
  • Header include settings
  • Linker settings

https://drive.google.com/open?id=1aha87gYvVHw7Efd3uu9ubghMulE015OW

Sample Program

Essentially the minimal publisher example which I ran in VS 2019 as a c++ console app:

#include <iostream>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

int main(int argc, char * argv[])
{
    rclcpp::init(argc, argv);
    std_msgs::msg::String message;
    auto node = rclcpp::Node::make_shared("minimal_publisher");
    auto publisher = node->create_publisher<std_msgs::msg::String>("topic", 10);
    auto publish_count = 0;

    rclcpp::WallRate loop_rate(1);

    while (rclcpp::ok()) {

        message.data = "Hello, world" + std::to_string(publish_count++);
        RCLCPP_INFO(node->get_logger(), "Publishing: '%s'", message.data.c_str());
        publisher->publish(message);
        rclcpp::spin_some(node);
        loop_rate.sleep();
    }
    rclcpp::shutdown();
}

Originally posted by stefan_ on ROS Answers with karma: 11 on 2019-12-18

Post score: 1


Original comments

Comment by gvdhoorn on 2019-12-18:\

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.

Comment by stefan_ on 2019-12-18:
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]

Comment by gururajvj7 on 2020-04-21:
I am also facing same issue. ROS2 crashes when trying to make a node (auto node = rclcpp::Node::make_shared("minimal_publisher")

Comment by TheBee on 2021-01-29:
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

Comment by Sid7117 on 2021-12-15:
Were you able to fix this issue?

Comment by TheBee on 2021-12-15:
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/ROSOnWindows/issues/310)

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.

Comment by Sid7117 on 2021-12-16:
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.

Comment by Sid7117 on 2021-12-16:
Hi, How do you call the functions in the wrapper.cpp in a program to publish to a topic?

Comment by TheBee on 2021-12-30:
Hey there! I've updated https://github.com/ItsMeTheBee/VisualStudioROS to also add sample code on how to call the wrapper functions (in the RosFromCSharp Solution)

Comment by osilva on 2021-12-30:
thank you @TheBee.

Comment by Sid7117 on 2022-01-18:
Thank you @TheBee

$\endgroup$
1

1 Answer 1

0
$\begingroup$

Rosanswers logo

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/ROSOnWindows/issues/310)

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/VisualStudioROS

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 =)


Originally posted by TheBee with karma: 46 on 2021-12-15

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by edgarmg on 2021-12-15:
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!

Comment by osilva on 2021-12-15:
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 :)

Comment by osilva on 2021-12-15:
Added a couple tags to your question to help future search

Comment by TheBee on 2021-12-30:
@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)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.