CLion and ROS: fatal error: ros/ros.h: No such file or directory
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/2374... , 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})
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 withcatkin build
command from terminal.Or at least this is how I do it with my workspaces built using
catkin build
command.That was exactly the problem! I did
catkin_init_workspace
in thesrc
directory and after that it worked perfectly. Thanks so much. If you post as answer I'll accept it :)