Visual Studios 2017 project with ROS2 components

asked 2019-02-13 14:41:08 -0500

bwolfe gravatar image

I'm trying to build a VS2017 application (specifically an Unreal Engine 4 app) that uses ROS2 but am having difficulty getting the ROS2 components into the project. I have downloaded and compiled ros2 from source using colcon and can run the defacto demo_nodes_cpp test apps to demonstrate it works. Now I want to pull that into a VS2017 application. I figured the libraries that were generated from colcon would be usable directly from VS but my attempts to link the VS project to the libraries hasn't worked. Alternatively, I tried using the VS File->New->Project from existing code from the top-level ros2 directory, but all those files confuse VS when it sees an xsd file and tries to "compile" that as well.

Realistically, I really only need the runtime part of ros2, but knowing what directories under ros2/src are strictly realtime code is not obvious. I've even tried the "Project from existing code" method to set up individual VS static libraries for each subdir of ros2/src but VS compilation gets confused about the include paths referenced by the code. For example, I made a standalone VS static library project for ros2/src/urdf/urdf. The new project pulls in the right includes and cpp files for urdf, but compilation gives me

c:\dev\ros2\src\ros2\urdf\urdf\src\model.cpp(42): fatal error C1083: Cannot open include file: 'urdf/model.h': No such file or directory

Bottom line, is there a known way of pulling in ros2 code into a VS2017 project either by referencing the libraries and includes generated from colcon or by compiling from source within VS? I know ros2 is only proven to work with VS2015, but I'm stuck with VS2017 due to the UE4 application I'm developing.

edit retag flag offensive close merge delete


I know ros2 is only proven to work with VS2015

That is incorrect. The ROS releases Crystal (Dec 2018) as well as Bouncy (Jun 2018) are built using Visual Studio 2017.

Dirk Thomas gravatar image Dirk Thomas  ( 2019-02-15 15:38:37 -0500 )edit

Dirk, you tell me it can be done, yet don't say how. I get compile errors with VS2017 by simply adding #include "rclcpp/rclcpp.hpp" to my simple UE4 actor class. .../rclcpp/event.hpp(41): error C4003: not enough arguments for function-like macro invocation 'check'

bwolfe gravatar image bwolfe  ( 2019-02-19 13:37:14 -0500 )edit

ROS packages use CMake to declare how a package is being built. We never create Visual Studio project files by hand. So I don't have a recommendation for you how to do that - you basically have to manually configure all dependencies (libraries, include directories, etc.).

Dirk Thomas gravatar image Dirk Thomas  ( 2019-02-19 13:46:49 -0500 )edit

As an alternative you could use CMake and then generate the Visual Studio files from that. Since most ROS packages use CMake you should be able to look at any of them as a template (or use ros2 pkg create to generate the stub).

Dirk Thomas gravatar image Dirk Thomas  ( 2019-02-19 13:48:37 -0500 )edit

In my original post I mentioned doing just that (i.e., create VS proj from cmake files), but what parts of the ros2 source are needed for compilation? There are 46 subdirs in ros2/src/ros2 and uncounted subdirs under that. Just looking for guidance on what's actually necessary for compilation.

bwolfe gravatar image bwolfe  ( 2019-02-20 09:35:26 -0500 )edit

It completely depends on what your packages wants to use. In case of the urdf error message you need to declare a dependency on that package in the manifest, find_package it in the CMake code and declare it as a dependency for the target you are building (using its include dirs and libs).

Dirk Thomas gravatar image Dirk Thomas  ( 2019-02-20 10:37:39 -0500 )edit