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.
First step: I create Helloworldexample in visual studio 2017.
Second step: I add paths C:\dev\ros2\include;
C:\dev\ros2\Lib; in the properties --> C/C++ --> General --> Additional Include Directories
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
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.
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.
open HelloWorldExample(VC++ Project) with open Visual Studio 15
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
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 ==========
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
go to C:\dev\ros2\examples-master\rclcpp\minimal_publisher\
mkdir build
cd build
cmake …\ -G “Visual Studio 14 2015 Win64”
open publisher_lambda(VC++ Project)
build
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 ==========
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.
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.