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

CMake cannot find source file

asked 2018-08-14 09:43:07 -0500

Old Meme gravatar image

updated 2018-08-14 10:46:00 -0500

gvdhoorn gravatar image

Hi guys,

I'm using ROS kinetic on a Navio2 board, and I've been working on a project in a catkin workspace. I edited the CMakeLists.txt file to add an executable, but every time I attempt to run catkin_make, I get the following error:

CMake Error at link/CMakeLists.txt:201 (add_executable):
   Cannot find sourcefile:


  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx

CMake Error: CMake can not determine linker language for target: roscomm
CMake Error: Cannot determine link language for target "roscomm".
-- Generating done
-- Build files have been written to: /home/pi/ros_ws/build
Invoking "cmake" failed

I know for sure that this file exists, and I've tried using just roscomm.cpp instead of link/src/roscomm.cpp.


The full path is ~/ros_ws/src/link/src/roscomm.cpp

The CMakeLists.txt is as follows:

cmake_minimum_required(VERSION )

find_package(catkin REQUIRED COMPONENTS  



add_executable(roscomm link/src/roscomm.cpp)
target_link_libraries(roscomm ${catkin_INCLUDE_DIRS})

Any help would be great, thanks

edit retag flag offensive close merge delete


Source file locations are always specified relative to the CMakeLists.txt that uses them, so what is the path to roscomm.cpp relative to link/CMakeLists.txt?

it might help if you show us your CMakeLists.txt (ie: the one in the link directory).

gvdhoorn gravatar image gvdhoorn  ( 2018-08-14 10:31:41 -0500 )edit

The full path is ~/ros_ws/src/link/src/roscomm.cpp I've edited the original text so that it can all fit in one place

Old Meme gravatar image Old Meme  ( 2018-08-14 10:37:04 -0500 )edit

Please add this information to your original question text. Use the edit button/link for that. Comments are too limited.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-14 10:41:01 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-14 10:42:14 -0500

gvdhoorn gravatar image

The full path is ~/ros_ws/src/link/src/roscomm.cpp

Without waiting on your edit: have you tried src/roscomm.cpp?

If CMakeLists.txt is in ~/ros_ws/src/link, then the path to roscomm.cpp relative to your CMakeLists.txt would be src/.

edit flag offensive delete link more



Note also: this is not a ROS issue, but a plain CMake one. For future questions it might be more appropriate to post such questions on a different forum (ie: one more focused on general CMake usage or software development).

gvdhoorn gravatar image gvdhoorn  ( 2018-08-14 10:43:53 -0500 )edit

That seems to have done the trick, thanks!

Old Meme gravatar image Old Meme  ( 2018-08-14 10:45:19 -0500 )edit

Question Tools

1 follower


Asked: 2018-08-14 09:43:07 -0500

Seen: 10,957 times

Last updated: Aug 14 '18