0
$\begingroup$

Rosanswers logo

I am having trouble using ROS Kinetic and CLion, specifically that CLion complains the following when trying to build.

fatal error: ros/ros.h: No such file or directory compilation terminated.

I saw the question https://answers.ros.org/question/237494/fatal-error-rosrosh-no-such-file-or-directory/, but the answers did not help me.

When I build from commandline using catkin build, everything builds successfully. I presume that CLion does not get the ROS environment variables, since it is the exact same error whether I source or not. I have looked at many tutorials and help pages, but none could solve the problem for me. I have tried the following:

1 Building from command line, sourcing and then launching CLion from same terminal

catkin build
source /opt/ros/kinetic/setup.bash
source devel/setup.bash
cd clion_dir/bin
./clion.sh

2 Adding source /opt/ros/kinetic/setup.bash to the following files

~/.bashrc
/etc/profile
~/.profile

3 Changing the Exec part of ~/.local/share/applications/jetbrains-clion.desktop

Exec=bash -i -c "~/applications/clion-2017.3.3/bin/clion.sh" %f

My CMakeLists.txt looks as follows

cmake_minimum_required(VERSION 2.8.3)
project(example)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package()

include_directories(${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})

add_executable(listener2 src/listener2.cpp)
target_link_libraries(listener2 ${catkin_LIBRARIES})

Originally posted by sonjabrits on ROS Answers with karma: 3 on 2018-02-14

Post score: 0


Original comments

Comment by l4ncelot on 2018-02-14:
I think CLion doesn't know how to compile your workspace when using catkin build instead of catkin_make. Try catkin_init_workspace in your workspace/src directory and load the created CMakeLists.txt with CLion. You can still build the package with catkin build command from terminal.

Comment by l4ncelot on 2018-02-14:
Or at least this is how I do it with my workspaces built using catkin build command.

Comment by sonjabrits on 2018-02-14:
That was exactly the problem! I did catkin_init_workspace in the src directory and after that it worked perfectly. Thanks so much. If you post as answer I'll accept it :)

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Try catkin_init_workspace in your workspace/src directory and load the created CMakeLists.txt with CLion. You can still build the package with catkin build command from terminal.


Originally posted by l4ncelot with karma: 826 on 2018-02-15

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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