ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Unable to load ROS2 workspace into CLion

asked 2019-03-27 15:27:09 -0500

jhassold gravatar image

I've been trying to get Ros2 to work with my copy of CLion using this guide on the Discussion Forums, but have been having no luck. I was wondering if there were more up-to-date instructions, since these were written in 2017. Or if I'm inadvertently messing something up. Probably the latter.

Before we start, this is all on Ubuntu version 18.04 LTE, running on a Lenovo ThinkPad P52.

So first off, the step for compilation seems to have a couple stderrors for me. I don't think they're the cause of my pain, but I'm a bit new to this, so who knows!

Starting >>> ament_package
Starting >>> ament_flake8
Starting >>> fastcdr
Starting >>> poco_vendor
Starting >>> ament_cppcheck
Starting >>> tinydir_vendor
Starting >>> gtest_vendor
Starting >>> osrf_pycommon
Starting >>> tinyxml2_vendor
Starting >>> tinyxml_vendor
Starting >>> urdfdom_headers
Starting >>> orocos_kdl
Finished <<< ament_package [0.97s]                                                                                                                                                               
Starting >>> ament_cmake_core
Finished <<< gtest_vendor [1.18s]                                                                                                                                                                   
Starting >>> gmock_vendor
Finished <<< gmock_vendor [0.24s]                                                                                                                                                            
Starting >>> osrf_testing_tools_cpp
Finished <<< poco_vendor [1.61s]                                                                                                                                                               
Starting >>> ament_pep8
Finished <<< ament_flake8 [2.03s]                                                                                                                                                                
Starting >>> ament_pep257
Finished <<< ament_cmake_core [1.54s]                                                                                                                                              
Starting >>> ament_cmake_test                                                                                                                                                      
Finished <<< ament_cppcheck [2.67s]                                                                                                                                                  
Starting >>> ament_cmake_libraries
Finished <<< tinyxml2_vendor [2.71s]
Finished <<< tinyxml_vendor [2.73s]
Finished <<< urdfdom_headers [2.76s]                                                                                                                                                   
Starting >>> ament_cmake_export_libraries
Starting >>> ament_cmake_include_directories
Starting >>> ament_cmake_export_definitions
Finished <<< osrf_pycommon [3.41s]                                                                                                                                                                   
Starting >>> ament_cmake_export_include_directories                                                                                                                                               
Finished <<< ament_cmake_test [1.85s]                                                                                                                                                               
Starting >>> ament_cmake_export_link_flags
Finished <<< ament_pep8 [2.88s]                                                                                                                                                                     
Starting >>> ament_cmake_python
Finished <<< ament_cmake_include_directories [2.23s]                                                                                                                                                  
Starting >>> ament_lint_auto
Finished <<< ament_cmake_libraries [2.41s]                                                                                                                                                            
Finished <<< ament_cmake_export_definitions [2.40s]                                                                                                                                                
Starting >>> ament_cmake_export_dependencies
Starting >>> ament_cmake_target_dependencies
Finished <<< ament_cmake_export_libraries [2.55s]                                                                                                                                                  
Starting >>> ament_cmake_export_interfaces                                                                                                                                                         
Finished <<< fastcdr [5.66s]                                                                                                                                                                            
Starting >>> fastrtps
Finished <<< ament_pep257 [3.96s]                                                                                                                                         
Starting >>> ament_copyright
Finished <<< ament_cmake_export_include_directories [3.61s]                                                                                         
Finished <<< ament_cmake_export_link_flags [2.81s]                                                                                                                                            
Starting >>> ament_index_python
Starting >>> ament_cmake_gtest
Finished <<< ament_cmake_python [4.27s]                                                                                                                                                 
Starting >>> ament_cmake_pytest                                                                                                                                                      
Finished <<< ament_copyright [3.01s]                                                                                                                                                 
Starting >>> ament_lint_cmake
Finished <<< ament_cmake_target_dependencies [5.25s]                                                                                                                                    
Finished <<< ament_cmake_export_dependencies [5.42s]                                                                                                                                 
Finished <<< ament_lint_auto [5.65s]
Finished <<< ament_cmake_export_interfaces [5.33s]
Starting >>> ament_cmake
Starting >>> ament_cpplint                                                                                                                                                                             
Starting >>> ament_xmllint
Starting >>> launch
Finished <<< ament_index_python [3.66s]                                                                                                                                          
Starting >>> ament_pyflakes                                                                                                                                                      
Finished <<< tinydir_vendor [11.9s]                                                                                                                                               
Starting >>> ament_clang_format                                                                                                                                                
Finished <<< ament_lint_cmake [5.24s]                                                                                                                                          
Finished <<< ament_cmake_pytest [5.55s]                                                                                                                                        
Finished <<< ament_cmake_gtest [7.18s]
Starting >>> ament_cmake_lint_cmake
Starting >>> ament_cmake_gmock                                                                                                                                                                
Starting >>> ament_pclint
Finished <<< ament_xmllint [5.40s]                                                                                                                                                             
Starting >>> ros_environment
Finished <<< ament_cmake [5.96s]                                                                                                                                                                 
Starting >>> uncrustify_vendor                                                                                                                                                      
Finished <<< ament_cmake_lint_cmake [2.33s]
Starting >>> ament_cmake_copyright
Finished <<< ament_cmake_gmock [2.34s]                                                                                                                                              
Starting >>> libyaml_vendor
Finished <<< ament_cpplint [6.25s]                                                                                                                                                     
Starting >>> console_bridge_vendor
Finished <<< ament_pyflakes [7.62s]                                                                                                                                                      
Starting >>> libcurl_vendor                                                                                                                                                                  
Finished <<< ros_environment [2.52s]                                                                                                                                                         
Starting >>> ament_cmake_auto
Finished <<< ament_cmake_copyright [3.01s]                                                                                                                                                    
Starting >>> ament_cmake_cppcheck                                                                                                                                                             
Finished <<< launch [9.10s]
Starting >>> ament_cmake_cpplint                                                                                                                                                                    
Finished <<< ament_clang_format [6.95s]                                                                                                                                                              
Starting >>> ament_cmake_flake8
Finished <<< osrf_testing_tools_cpp [20.9s]                                                                                                                                                                
Starting >>> ament_cmake_pep257
Finished <<< ament_cmake_auto [3.87s]                                                                                                                                                      
Starting >>> ament_cmake_xmllint
Finished <<< ament_pclint [8.25s]                                                                                                                                                          
Starting >>> rviz_assimp_vendor
Finished <<< ament_cmake_cpplint [3.38s]                                                                                                                                                                  
Starting >>> rviz_ogre_vendor
Finished <<< ament_cmake_cppcheck [3.68s]                                                                                                                                                                 
Starting >>> yaml_cpp_vendor
Finished <<< ament_cmake_flake8 [3.38s]                                                                                                                                                                   
Starting >>> test_osrf_testing_tools_cpp
Finished <<< ament_cmake_pep257 [3.53s]                                                                                                                                       
Starting >>> ament_cmake_nose
Finished <<< orocos_kdl [26.3s]                                                                                                                                                 
Starting >>> ament_cmake_clang_format
Finished <<< ament_cmake_xmllint [3.81s]                                                                                                                                               
Starting >>> ament_cmake_pclint
Finished <<< libcurl_vendor [9.30s]                                                                                                                                                       
Starting >>> ament_cmake_pep8                                                                                                                                                             
Finished <<< ament_cmake_nose [2.78s]                                                                                                                                                     
Starting >>> ament_cmake_pyflakes                                                                                                                                                         
Finished <<< ament_cmake_clang_format [3.51s]                                                                                                                                             
Finished <<< ament_cmake_pclint [3.48s]                                                                                                                                                   
Finished <<< ament_cmake_pep8 [3.15s]                                                                                                                                                     
Finished <<< ament_cmake_pyflakes [3.33s]                                                                                                                                                 
Finished <<< rviz_assimp_vendor [9.36s]                                                                                                                                                   
Finished <<< libyaml_vendor [17.1s]                                                                                                                                                         
Finished <<< test_osrf_testing_tools_cpp [25.1s]                                                                                                                                           
Finished <<< yaml_cpp_vendor [27.7s]                                                                                                                                                       
Finished <<< console_bridge_vendor [35.7s]                                                                                                                                                
Starting >>> urdfdom
Finished <<< uncrustify_vendor [45.3s]                                                                                                                                         
Starting >>> ament_uncrustify
Finished <<< ament_uncrustify [0.95s]                                                                                                                            
Starting >>> ament_cmake_uncrustify ...
(more)
edit retag flag offensive close merge delete

Comments

CLion has JUST added support for compilation databases, and external build tools. I'm currently experimenting on seeing if these can solve the issue, and will report back.

If anyone has experience generating top-level compilation database files via colcon, please let me know.

FURTHER UPDATE Colcon is indeed able to generate compilation databases. However, it makes one for each package, and I can't figure out how to get one in the root directory that covers all of them.

jhassold gravatar image jhassold  ( 2019-03-29 13:45:27 -0500 )edit

5 Answers

Sort by ยป oldest newest most voted
1

answered 2019-04-01 12:54:53 -0500

jhassold gravatar image

After significant fighting, I have not been able to successfully get the entire workspace into CLion. However, you can still work with packages individually by opening their respective CMakeLists.txt files as projects.

It's theoretically possible to open the entire workspace if there's a top-level CMakeLists.txt file. But I'm not sure how feasible that is to implement, given the amount of trouble I've had with it.

edit flag offensive delete link more
1

answered 2020-02-24 11:26:09 -0500

guru_florida gravatar image

updated 2020-10-12 12:31:37 -0500

I would not want to compile the ROS2 core using this, but I compile my own workspace of ROS2 nodes using this CMakeLists.txt file in my workspace root. It finds sub-projects automatically like colcon does. You will have to setup the CLion build and run environment variables created using the source <path-to>/install.bash workspace overlay scripts. See far below, I also created a bash script to print out all the env vars from a properly setup shell so I can then just copy/paste into CLion.

I also have CLion developing ROS nodes on an RPI remotely from my desktop linux using the remote-ssh toolchain. Just generate your env vars from the RPi instead of local system and this works great.

FYI I didnt write this CMakeLists.txt, so I don't deserve any credit for it. :)

cmake_minimum_required(VERSION 3.13)
project("MyROSProject")

# usually I put this in a separate file include("/opt/ros/_common/Colcon.cmake")
function(colcon_add_subdirectories)
  cmake_parse_arguments(PARSE_ARGV 0 "ARG" "" "BUILD_BASE;BASE_PATHS" "")

  message("search criteria: ${ARGV}")

  execute_process(COMMAND colcon list
        --paths-only
        --base-paths ${ARG_BASE_PATHS}
        --topological-order
        ${ARG_UNPARSED_ARGUMENTS}
        OUTPUT_VARIABLE paths)
  string(STRIP "${paths}" paths)
  string(REPLACE "\n" ";" paths "${paths}")

  MESSAGE("colcon shows paths ${paths}")

  foreach(path IN LISTS paths)
    message("...examining ${path}")
    # if(EXISTS "${path}/CMakeLists.txt")
    execute_process(COMMAND colcon info --paths "${path}" OUTPUT_VARIABLE package_info)
    if(NOT "${package_info}" MATCHES "type:[ \t]+(cmake|ros.ament_cmake|ros.cmake)")
      message("skipping non-cmake project")
    elseif(NOT "${package_info}" MATCHES "name:[ \t]+([^ \r\n\t]*)")
      message(WARNING "could not identify package at ${path}")
    else()
      set(name "${CMAKE_MATCH_1}")
      message("...adding package ${name} from path ${path}")
      MESSAGE("package info: ${package_info}")

      get_filename_component(BUILD_PATH "${name}" ABSOLUTE BASE_DIR "${ARG_BUILD_BASE}")

      add_subdirectory("${path}" "${BUILD_PATH}")
    endif()
  endforeach()
endfunction()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/humanoid/cmake" CACHE STRING "Modules for CMake" FORCE)

colcon_add_subdirectories(
        BUILD_BASE "${PROJECT_SOURCE_DIR}/humanoid/build"
        BASE_PATHS "${PROJECT_SOURCE_DIR}/humanoid/lib/"
        --packages-select LynxmotionLSS
)

colcon_add_subdirectories(
    BUILD_BASE "${PROJECT_SOURCE_DIR}/humanoid/build"
    BASE_PATHS "${PROJECT_SOURCE_DIR}/humanoid/src/"
    --packages-select humanoid_model_msgs lss_joint_publisher humanoid_dynamic_model
)

You could just setup Workspace overlays, then run CLion bin, or modify your project to include the required env vars. Use this bash script for echo'ing the ROS2 related env vars needed in CLion:

 ros_env="AMENT_PREFIX_PATH CMAKE_PREFIX_PATH COLCON_PREFIX_PATH PKG_CONFIG_PATH PYTHONPATH LD_LIBRARY_PATH PATH ROS_DISTRO ROS_PYTHON_VERSION ROS_LOCALHOST_ONLY ROS_VERSION"
 for e in ${ros_env}; do
     echo "$e=${!e}"
 done

These ENV settings must be pasted into 2 locations in CLion, once for building and then for each program executable runtime environment:

  • File | Settings... | Build, Execution, Deployment | CMake into the Environment editor dialog (now refresh CMake project)
  • Run | Edit Configurations... | <program> | Environment variables editor dialog
edit flag offensive delete link more
0

answered 2020-05-21 15:56:04 -0500

madmax gravatar image

Well, you can open your whole workspace and then just go to the projects CMakeLists file and right click load the project.
That way you can move between your workspace files and stuff easily and also build packages.

Not all in one, but at least the whole repo in clion.

edit flag offensive delete link more
0

answered 2020-05-21 17:48:22 -0500

ruffsl gravatar image

The way I use Clion and Qt Creator for c++ projects in ros2 is by first building my overlay workspace via --symlink-install using colcon, then opening a new shell to source install space for the newly built workspace and then launch Clion or Qt Creator via that shell environment and pointing it to the CMakeLists.txt for the particular package I'd like to work on. I then also change the cmake build directory under the setting menu to point to the same build/<package_name> directory that colcon stores the build artifacts, such that colcon and the IDE share the same build cache, and that the symlinks in the install folder point to the same binaries that my IDE builds. This also helps when using orchestration tools to run your nodes like ros2 launch or ros2 run.

https://intellij-support.jetbrains.co...

https://doc.qt.io/qtcreator/creator-b...

This allows me the use of code completion and introspection as normal without having to patch any Cmake files. You can also open multiple Cmake projects if the IDE supports this, although Clion only starts one process, so the first shell you launch the Clion from will dictate the environment variables that process will inherit, making it tricky to work on packages from non-overlaping workspaces simultaneously.

This same approach of launching IDEs from a workspace sourced shell works fine for me when using python and Pycharm or JupyterLab as well. Just be sure your IDE build/install artifacts coincide with the workspace, so that changes are appropriately reflected by other ros tools or overlay workspaces that may source the current one as an underlay workspace.

Pro-tip: if you run node your debugging via ros-launch, and it crashes, the traceback includes the command line arguments that roslaunch passed to node's executable, e.g. paths or all the temp yaml files that encode all the parameters and re-mapping logic ros launch does when resolving launch configurations. You could then just copy and paste those arguments to the appropriate setting field for the IDE that could then be passed to your executable when using the debugger under gdb.

This helps if the node is crashing before you get the chance to attach to the node's process, or when you'd rather not kill the rest of the launch file that may have other nodes like camera drivers or static tf publishers that you don't want to start manually. Just note that if you reboot or change the launch file per that node, you'll have to update the debug args in the IDE, given the previously temporarily yaml files may then be cleared or outdated.

edit flag offensive delete link more
0

answered 2020-03-18 07:32:52 -0500

Matous Pokorny gravatar image

Hello,

thank you very much @guru_florida. Your post and original CMakeLists file helped me a lot. I can build all packages in workspace but code completion does not work. I did these steps:

  1. Copy the original CMakeLists file into my workspace and comment out the line selecting specific packages--packages-select
  2. Open project from this CMakeLists file into in CLion
  3. List environment variables using simple script above
  4. Copy listed environment variables into CLion settings
  5. Build the project
edit flag offensive delete link more

Question Tools

4 followers

Stats

Asked: 2019-03-27 15:27:09 -0500

Seen: 1,388 times

Last updated: Oct 12 '20