Ask Your Question
1

Why isnt my executable compiling?

asked 2019-01-13 08:17:57 -0500

TristanNoctis gravatar image

updated 2019-01-13 09:26:05 -0500

So right now, I have two executables within one package. I had created the first executable a few days back. But after creating the second executable and using the catkin_make command, only the first program gets compiled and not the second. What am I doing wrong? Is it because of the two executables within one package? Also, if I type rosrun package executable2, I get the following error - "Couldn't find executable names executable2"

My Cmake file -

cmake_minimum_required(VERSION 2.8.3)
project(first_package)
find_package(catkin REQUIRED COMPONENTS roscpp geometry_msgs)
catkin_package()
include_directories(${catkin_INCLUDE_DIRS})
add_executable(hello hello.cpp pubvel pubvel.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})

I am pretty sure the error is due to the add_executable part of my CMakeLists.txt. hello.cpp is the first executable whereas pubvel.cpp is the second executable.

edit retag flag offensive close merge delete

Comments

Can you update your question will your CMakeLists.txt file, and the details of the source files that are needed to compile each executable. We can't help you if we don't know how your workspace is setup.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-01-13 08:32:06 -0500 )edit

We need to see your CMakeLists.txt. As to your last sentence, have you sourced your catkin_ws and restarted the terminal?

Hypomania gravatar image Hypomania  ( 2019-01-13 09:19:24 -0500 )edit

Hey I have updated my CMakeLists.txt. Can you please check?

TristanNoctis gravatar image TristanNoctis  ( 2019-01-13 09:26:26 -0500 )edit

This is my other workspace that I have created other than the 'catkin_ws'. And yes I have sourced it before using the catkin_make

TristanNoctis gravatar image TristanNoctis  ( 2019-01-13 09:27:50 -0500 )edit

Try the first part of my answer.

Hypomania gravatar image Hypomania  ( 2019-01-13 09:39:05 -0500 )edit

Also try adding new add_executable and target_link_libraries for pubvel instead of merging them into one (I am not sure if you can do what you are doing).

Hypomania gravatar image Hypomania  ( 2019-01-13 09:45:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-01-13 09:38:15 -0500

Hypomania gravatar image

updated 2019-01-15 08:00:52 -0500

You have to add appropriate CMake macros at the end of your CMakeLists.txt file:

At the very bottom add these two lines for each executable:

  1. add_executable(node_name src/file_name.cpp)
  2. target_link_libraries(node_name ${catkin_LIBRARIES})

This will tell catkin to build and install the executable in your devel/lib/package_name directory.

If none of the above works I am presuming there's something wrong with your ROS install. Providing your CMakeLists.txt file would be helpful.

EDIT: Update your CMakeLists.txt to:

add_executable(hello src/hello.cpp
target_link_libraries(hello ${catkin_LIBRARIES}

add_executable(pubvel src/pubvel.cpp
target_link_libraries(pubvel ${catkin_LIBRARIES}

Ensure your src is stored in ~/your_ws/src/your_package/src directory.

edit flag offensive delete link more

Comments

Although you're correct in the end that the problem was with the add_executable tags in CMakeLists.txt. You absolutely do not have to re-source your workspace every time you run catkin_make.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-01-13 16:59:36 -0500 )edit

Your update to the CMakeLists.tst worked! Only problem now is that I have to source the setup.bash each time I open a new terminal.

TristanNoctis gravatar image TristanNoctis  ( 2019-01-13 23:28:01 -0500 )edit

@PeteBlackerThe3rd, my apologies, I was meant to say everytime you build a new package, where a new devel and build folders are created!

Hypomania gravatar image Hypomania  ( 2019-01-14 01:16:32 -0500 )edit

@TristanNoctis, you don't, just follow the steps I added in part 1.

Hypomania gravatar image Hypomania  ( 2019-01-14 01:17:08 -0500 )edit
1

@Hypomania no problem, could you update your answer so it doesn't include the part about sourcing the work space. It's quite confusing at the moment, as the first half doesn't answer the OPs question and is incorrect. The second half in great though.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-01-14 01:37:42 -0500 )edit

@PeteBlackerThe3rd, initially I thought his ws wasn't source. If it's not sourced it won't get recognized by bash (correct me if I am wrong), is that still irrelevant to the question?

Hypomania gravatar image Hypomania  ( 2019-01-14 02:38:30 -0500 )edit

That's true, but the question was about compiling multiple binaries. The first binary was okay, then the problem appeared when they tried to compile a second binary. Plus the actual fault in this case was the CMakeLists.txt so that should be the focus of the answer.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-01-14 02:58:16 -0500 )edit

@PeteBlackerThe3rd, that makes sense, I will edit it out.

Hypomania gravatar image Hypomania  ( 2019-01-15 08:00:32 -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

Stats

Asked: 2019-01-13 08:17:57 -0500

Seen: 345 times

Last updated: Jan 15 '19