0
$\begingroup$

Rosanswers logo

I have a fresh install of all - Ubuntu, CLion and ROS Melodic, and I am having troubles with how CLion handles the headers

I have a package called maze_controller, which contains a custom service and a robot controller

compiling works without a problem, but CLion, for some reason, reports that it can't find a message.h header, even tho it is in devel/include and the code compiles fine despite that... as you might already guess, the message used is also reported as unknown, but catkin compiles the code juuust fine...

is there a way to fix this? I don't remember having such issue before I updated everything (coming from Lunar and Ubuntu 16.04)

yes, CLion is opened from a terminal with sourced workspace yes, project was built before yes, I tried deleting .idea

CMake for the package:

cmake_minimum_required(VERSION 2.8.3)
project(maze_controller)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  message_generation
  roscpp
  std_msgs
)

add_service_files(
        FILES
        movement.srv
)

generate_messages(
        DEPENDENCIES
        std_msgs
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES maze_controller
  CATKIN_DEPENDS roscpp std_msgs message_runtime
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

add_library(${PROJECT_NAME} src/virtual_controller.cpp src/real_controller.cpp)
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})

add_executable(${PROJECT_NAME}_test_sim src/virtual_controller_test.cpp)
target_link_libraries(${PROJECT_NAME}_test_sim ${PROJECT_NAME})

add_executable(${PROJECT_NAME}_test src/real_controller_test.cpp)
target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME})

## Mark executables and/or libraries for installation
install(TARGETS ${PROJECT_NAME}
        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
        )

## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
        DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
        FILES_MATCHING PATTERN "*.h"
        PATTERN ".svn" EXCLUDE
        )

image description


Originally posted by SEnergy on ROS Answers with karma: 11 on 2019-09-21

Post score: 0


Original comments

Comment by gvdhoorn on 2019-09-21:
Please attach your screenshot to the question directly. I've given you sufficient karma for that.

Comment by gvdhoorn on 2019-09-21:
I don't know whether CLion needs it, but there is no add_dependencies(..) anywhere in your CMakeLists.txt.

Refer to Catkin documentation: Building messages, services or actions for why this needed and how to add it.

Comment by SEnergy on 2019-09-21:
@gvdhoorn I just went over http://wiki.ros.org/catkin/CMakeLists.txt and made slightly different CMake file (basically the same, but with the add_dependencies), I will update question asap

Comment by gvdhoorn on 2019-09-21:
And just to make sure: you have seen wiki/IDEs - CLion?

Comment by SEnergy on 2019-09-21:
yes... I never had this problem before when I was using Ubuntu 16.04 and Lunar, however I just switched to 18.04 and Melodic... I am also using CLion only as an editor, and still manually compile using catkin_make... I use CLion for it's autocomplettion, but it doesn't work with the custom messages/services anymore for some reason

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I didn't really realize this, as I've been using CLion only for editing, not for compiling & running, but I still had to set the generation path and cmake options for ROS according to this http://wiki.ros.org/IDEs#CLion

I've also been missing the add_dependencies() macro for my lib

after adding those 2, CLion seems to be able to find the custom service header


Originally posted by SEnergy with karma: 11 on 2019-09-21

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.