ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

ROS2 application development in visual studio 2017 or 2015 (win 10 x64)

Hi everyone,

I want to start ROS2 development in visual studio 2017 or 2015. However, i encouner some problems so that I can’t build my source code.

1. First step: I create Helloworldexample in visual studio 2017.
2. Second step: I add paths C:\dev\ros2\include;
C:\dev\ros2\Lib; in the properties --> C/C++ --> General --> Additional Include Directories
3. Third step: I add fies: C:\dev\ros2\Lib\libfastrtps-1.5.lib;
C:\dev\ros2\Lib\libfastcdr-1.0.lib; in the properties --> Linker --> Input --> Additional Dependencies
4. Forth step:Build --> error info below

1>------ Rebuild All started: Project: Project1, Configuration: Debug x64 ------
1>HelloWorld_main.cpp
1>HelloWorldSubscriber.cpp
1>HelloWorldPubSubTypes.cxx
1>HelloWorldPublisher.cpp
1>HelloWorld.cxx
1>Generating Code…
1>libfastrtps-1.5.lib(ThroughputControllerDescriptor.obj) : error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’ in HelloWorld.obj
1>libfastrtps-1.5.lib(ThroughputControllerDescriptor.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MD_DynamicRelease’ doesn’t match value ‘MDd_DynamicDebug’ in HelloWorld.obj
1>libfastrtps-1.5.lib(ParameterTypes.obj) : error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’ in HelloWorld.obj
1>libfastrtps-1.5.lib(ParameterTypes.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MD_DynamicRelease’ doesn’t match value ‘MDd_DynamicDebug’ in HelloWorld.obj
1>libfastrtps-1.5.lib(QosPolicies.obj) : error LNK2038: mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’ in HelloWorld.obj

As mentioned in the Windows Development Setup instructions we only test with Visual Studio 2015 at the moment. So I would highly recommend you to follow the instructions / stick to the same versions especially when using ROS 2 the first time.

Hi Thomas,

I have already tried it in the visual studio 2015. The problem still exists.

It is not sufficient to just manually add include directories and link arguments that you have added.

The easiest thing to do right now would be to start with a cmake package, generate a visual studio project from that and work from there. That way you get the correct include directories and linker flags that you need based on what you’re using. That flags will change depending on what you’re using. If for instance you start out only using rclcpp, but then later also need to use messages from sensor_msgs then your include and linker flags will change. So specifying them manually is not advisable.

Thanks for your tips. I have tried:

1. go to C:\dev\ros2\examples\c++\HelloWorldExample
2. mkdir build
3. cd build
4. cmake …\ -G “Visual Studio 14 2015 Win64”
5. open HelloWorldExample(VC++ Project) with open Visual Studio 15
6. I add fies: C:\dev\ros2\Lib\libfastrtps-1.5.lib;
C:\dev\ros2\Lib\libfastcdr-1.0.lib; in the properties --> Linker --> Input --> Additional Dependencies
7. Build

Error Info:
2>------ Rebuild All started: Project: HelloWorldExample, Configuration: Debug x64 ------
2> Building Custom Rule C:/dev/ros2/examples/C++/HelloWorldExample/src/HelloWorldExample/CMakeLists.txt
2> CMake does not need to re-run because C:/dev/ros2/examples/C++/HelloWorldExample/src/HelloWorldExample/build_2/CMakeFiles/generate.stamp is up-to-date.
2> HelloWorld.cxx
2> HelloWorldPubSubTypes.cxx
2> HelloWorldPublisher.cpp
2> HelloWorldSubscriber.cpp
2> HelloWorld_main.cpp
2> Generating Code…
2>LINK : fatal error LNK1104: cannot open file ‘libfastcdrd-1.0.lib’
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

I think it is the best thing that you can create some tutorials for users of ROS2.

Can you try to build in Release mode rather than Debug (can be selected in the tool bar at the top of the VS window) ?

If you build in Debug mode you need to add the debug libraries (note the trailing d) “libfastcdr-1.0d.lib”. Our binaries provide only the Release libraries so you’ll need to build the stack from source if you want to build Debug libraries.

Also, If you want to try ROS2 examples and build on top of them I encourage you to look at the examples in https://github.com/ros2/examples/. The examples you are trying to build right now are pure Fast-RTPS examples (installed by Fast-RTPS) and don’t use ROS 2

Thank you for your answers.
HelloWorldExample: you are right! If i switched into Release, it works.!

Hi marguedas:

I tried to build this example https://github.com/ros2/examples/:

1. download https://github.com/ros2/examples/ into dictionary C:\dev\ros2
2. open developer cmd prompt for VS2015
3. go to C:\dev\ros2\examples-master\rclcpp\minimal_publisher\
4. mkdir build
5. cd build
6. cmake …\ -G “Visual Studio 14 2015 Win64”
7. open publisher_lambda(VC++ Project)
8. build
9. error info:
1>------ Build started: Project: ZERO_CHECK, Configuration: Release x64 ------
1> Checking Build System
1> CMake does not need to re-run because C:/dev/ros2/examples-master/rclcpp/minimal_publisher/build/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: publisher_lambda, Configuration: Release x64 ------
2> Building Custom Rule C:/dev/ros2/examples-master/rclcpp/minimal_publisher/CMakeLists.txt
2> CMake does not need to re-run because C:/dev/ros2/examples-master/rclcpp/minimal_publisher/build/CMakeFiles/generate.stamp is up-to-date.
2> lambda.cpp
2>C:\dev\ros2\examples-master\rclcpp\minimal_publisher\lambda.cpp(35): warning C4002: too many actual parameters for macro 'RCLCPP_INFO’
2>C:\dev\ros2\examples-master\rclcpp\minimal_publisher\lambda.cpp(35): error C2039: ‘get_logger’: is not a member of 'MinimalPublisher’
2> C:\dev\ros2\examples-master\rclcpp\minimal_publisher\lambda.cpp(24): note: see declaration of 'MinimalPublisher’
2>C:\dev\ros2\examples-master\rclcpp\minimal_publisher\lambda.cpp(35): error C2039: ‘__this’: is not a member of 'MinimalPublisher’
2> C:\dev\ros2\examples-master\rclcpp\minimal_publisher\lambda.cpp(24): note: see declaration of ‘MinimalPublisher’
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

this example run in Release mode.

You need to stick to consistent version across different packages. I assume you installed the latest release ardent. Then you should also fetch the ardent branch of the examples repo. Otherwise the code on the master branch might already use / require changes made since the release.

Hi Thomas,

Thanks for your reminders.
I have tried example-ardent branch. But those problems still exist.

Our CI system builds the current default branches successfully and was able to build the ardent branches for the release. So chances are that something is different on your system.

You might want to double check which versions of all packages are being used, try to wipe the workspace and build it again, look into the include directories being used (in this case the node.hpp header from the rclcpp package). Often posting the very exact steps you are running might allow other to reproduce the problem or you to determine where your process is different from the instructions.