Ask Your Question

catkin_make builds executable in the wrong directory?

asked 2015-08-01 15:13:47 -0500

utagai gravatar image

updated 2015-08-02 22:26:18 -0500

Hello! I have a package I have been able to successfully build using catkin_make after setting up my package.xml and CMakeLists.txt. However, I have one problem. When I run catkin_make, it successfully makes the executable, but places the executable in catkin_ws/build/package_name. For example, I have made a small example below (tbrandom and tbsub are my executables):

may@MooMoo:~/Desktop/Tree/Programming/ros/TurtleBotRandom$ ls
build  devel  src
may@MooMoo:~/Desktop/Tree/Programming/ros/TurtleBotRandom$ cd build
may@MooMoo:~/Desktop/Tree/Programming/ros/TurtleBotRandom/build$ ls
catkin            catkin_make.cache  cmake_install.cmake  Makefile
catkin_generated  CMakeCache.txt     CTestTestfile.cmake  test_results
CATKIN_IGNORE     CMakeFiles         gtest                turtle_bot_random
may@MooMoo:~/Desktop/Tree/Programming/ros/TurtleBotRandom/build$ cd turtle_bot_random
may@MooMoo:~/Desktop/Tree/Programming/ros/TurtleBotRandom/build/turtle_bot_random$ ls
catkin_generated  cmake_install.cmake  Makefile  tbsub
CMakeFiles        CTestTestfile.cmake  tbrandom

When I source the devel/setup.bash, and try to run the executable through the package, ROS cannot find the executable unless I copy the executable(s) made (in this example, tbrandom and tbsub) and copy them into Desktop/Tree/Programming/ros/TurtleBotRandom/src/turtle_bot_random. This is really annoying for bigger projects which require more compile time, and then require me to copy paste files in between to actually start testing to see if my code even works.

What could be the reason or a potential fix? Am I doing something wrong? I've only started toying with catkin last night.


edit retag flag offensive close merge delete



If you post your CMakeLists.txt file I might be able to tell you what you need to do differently.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-08-01 16:42:31 -0500 )edit

+1 to what Dirk said: without your actual CMakeLists.txt we can only guess what is going on.

I'll take a guess though: was this package migrated from rosbuild? I've seen pkgs that forced rosbuild to place binaries in non-standard places. Catkin is different, and those pkgs then break.

gvdhoorn gravatar image gvdhoorn  ( 2015-08-02 01:26:38 -0500 )edit

Hello guys, I have posted a link to a pastebin of my CMakeLists.txt file (it was too long to copy paste into the post). I hope this helps!

utagai gravatar image utagai  ( 2015-08-02 22:27:34 -0500 )edit

Your Cmake ist worng

Declare a cpp executable

  • # add_executable(turtle_bot_random_node src/turtle_bot_random_node.cpp)

you can not bild a Comment

duck-development gravatar image duck-development  ( 2015-08-02 22:51:16 -0500 )edit

duck-development, if you look at lines 8-12, you will see that I have lines for my builds uncommented. I think you are looking at a line I commented out previously. I think I tried that thinking if I put in the path it would build the executable there, but commented it out when it didn't work.

utagai gravatar image utagai  ( 2015-08-02 23:04:49 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-08-02 23:18:55 -0500

Dirk Thomas gravatar image

The problem is that you call add_executable() before catkin_package() in the CMake file.

Please read the documentation for more information:

edit flag offensive delete link more


Thank you! That fixed the problem! However, the documentation doesn't seem to tell me why this caused an issue. Can you explain?

utagai gravatar image utagai  ( 2015-08-02 23:32:54 -0500 )edit

Because the catkin_package() call changes the default location of compiled targets.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-08-03 00:23:24 -0500 )edit

Is this because catkin_package() overwrites the location to which the executables should be save?

utagai gravatar image utagai  ( 2015-08-03 01:43:36 -0500 )edit


William gravatar image William  ( 2015-08-03 02:06:25 -0500 )edit

Alright, that makes sense. Thanks so much!

utagai gravatar image utagai  ( 2015-08-03 04:06:22 -0500 )edit

answered 2015-08-02 22:53:39 -0500

duck-development gravatar image

The catkin_ws/build/package_name is the Right Direcory, you run programms with rosrun an without sudo?

edit flag offensive delete link more


No, the build folder is the wrong locations for executables and libraries build with catkin. They are supposed to be created in the devel folder.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-08-02 23:19:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-08-01 15:13:47 -0500

Seen: 3,466 times

Last updated: Aug 02 '15