Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS2 Development with Visual Studio #310

Closed
ItsMeTheBee opened this issue Feb 3, 2021 · 6 comments
Closed

ROS2 Development with Visual Studio #310

ItsMeTheBee opened this issue Feb 3, 2021 · 6 comments
Assignees
Labels
Foxy help wanted Extra attention is needed ROS2 ROS2 related issues

Comments

@ItsMeTheBee
Copy link

ItsMeTheBee commented Feb 3, 2021

Hey there!

I want to incorporate ROS into another Windows project where colcon is not an option.
So I tried to write and run a simple C++ publisher in Visual Studio with a setup like this one:

  • 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 output

As far as I can see linking is not a problem, but there are two issues right now.
First problem is that I dont habe any pdb files, which means that I can´t debug into ROS.
Would you happen to have these files at hand?

The second issue is that it seems like I get an rclcpp::exceptions::RCLInvalidROSArgsError::RCLInvalidROSArgsError() exception when calling the init function. I tried to call rclcpp::init(0, nullptr); and I tried to build argv myself to pass the path to the .exe file of the Visual Studio project or a working ROS node from my workspace but everything results in this exception.

I don´t expect you to know much about solving this second issue but maybe you happen to have a clue since you work with Windows and ROS.

Apart from that any information about how to run ROS in a Visual Studio Project would be great.

@ooeygui
Copy link
Member

ooeygui commented Feb 3, 2021

Hi @ItsMeTheBee,
Thank you for your interest in ROS on Windows. We are always interested in talking with users of ROS on Windows and would love to know more about your project. Let me know if you are able to chat about it.

When building with cmake on Windows, pdbs are not typically generated for release builds. If you compile debug, you will have mismatches in the binaries. The ROS2 libraries you are importing into your C++ project were likely built without PDBs. If you need to debug ROS2 binaries, you'll need to rebuild them with --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo.

For the second bug, I suspect that you maybe crossing toolchains. If you install ROS2 from the Microsoft chocolatey distribution (http://aka,ms/ros) these are built with the v142 toolchain. You'll need to make sure that is selected. (When building within the ROS environment, we take care of this for you)

If you can share a sample project, we can diagnose further.

Be well,
Lou

@ooeygui ooeygui added Foxy ROS2 ROS2 related issues labels Feb 3, 2021
@ooeygui ooeygui self-assigned this Feb 3, 2021
@ooeygui ooeygui added the help wanted Extra attention is needed label Feb 3, 2021
@ItsMeTheBee
Copy link
Author

ItsMeTheBee commented Mar 2, 2021

Hey @ooeygui !

Thanks for your answer, I´ve been a bit busy but now I got some more infos.
I checked and the v142 toolchain is already selected.
I managed to build the debug binaries (just FYI I had some issues installing xmllint, not sure if it was my fault or if the tutorial for building ROS on windows is outdated but I needed to build zlib.lib myself).

The issues in rclcpp::init(0, nullptr); happened because I needed to add the path to the ROS binaries to my environment path.
Now I´m getting a "Invalid node name" error. I debugged around a bit and it seems like some characters are added which then lead to that error. Not sure where these characters come from, I added a screenshot of the contents of node_name when I build the class like this: MinimalPublisher():Node("").

debug_ros_3

Here another screenshot of the contents of node_name when I use MinimalPublisher():Node("pub").

debug_ros_2

I'm not sure how to share a sample project since all the ROS files (lib, dll, etc) are linked. I´ll try to push it into a new repo and send you the link.

Thanks a lot for your help!

@ooeygui
Copy link
Member

ooeygui commented Mar 2, 2021

Thank you for the update and screen shots. I'm going to need to be able to reproduce this locally in order to help solve the mystery,

Typically when I see this, it is either a toolchain mismatch (which you ruled out), a calling convention problem (Which shouldn't be the case due to ROS2 code being explicitly tagged), or an optimization problem. The latter are really hard to diagnose because the generated code doesn't actually match what is written.

If you can step through the crossing, you can use the Memory and disassembly windows to see where things go off the rails.

If you can't share your project, I can also do a one on one debugging session with you on your system if you are comfortable. Let me know, and I'll figure out how to contact you about setting that up.

@ItsMeTheBee
Copy link
Author

I think you can replicate the error with the code here . The ReadMe should contain everything you need to know.
If this doesn´t work we can do a debugging session as well =)

@ItsMeTheBee
Copy link
Author

Hahaha I feel kind of dumb for not trying this sooner, but I just changed the Solution Config to "Release" and it worked :D
Sometimes it's the simple things^^

@ooeygui
Copy link
Member

ooeygui commented Mar 8, 2021

Ah, I should have had that on the list too - sorry about that. I'm glad it's resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Foxy help wanted Extra attention is needed ROS2 ROS2 related issues
Projects
None yet
Development

No branches or pull requests

2 participants