Ask Your Question
1

Rosrun can not find an executable file.

asked 2019-12-13 13:29:45 -0600

Parth2851 gravatar image

updated 2019-12-15 08:11:33 -0600

So I have a package called dijkstra, it contains a cpp program in the src folder called algorithm_1.cpp which I need to run.

First I run the command source devel/setup.bash to set up the environment. After that I do, rosrun dijkstra and press tab twice, but it doesn't find any executable file.

This is the CMake-

cmake_minimum_required(VERSION 2.8.3)
project(dijkstra)

find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
geometry_msgs
)

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(${PROJECT_NAME} src/algorithm_1.cpp)

target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)

EDIT-

This is the error I get -

parth@Parth:~/catkin_ws/src$ rosrun dijkstra dijkstra.cpp
[rosrun] Couldn't find executable named dijkstra.cpp below /home/parth/catkin_ws/src/dijkstra
[rosrun] Found the following, but they're either not files,
[rosrun] or not executable:
[rosrun]   /home/parth/catkin_ws/src/dijkstra/src/dijkstra.cpp
edit retag flag offensive close merge delete

Comments

@rubicks: it would also have worked if you would've updated your answer.

gvdhoorn gravatar imagegvdhoorn ( 2019-12-15 12:44:46 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-12-15 09:54:06 -0600

gvdhoorn gravatar image

updated 2019-12-15 11:38:08 -0600

it contains a cpp program in the src folder called algorithm_1.cpp which I need to run.

this would appear to be the cause of your problem: .cpp files are not programs. They are source files which must be compiled into binaries first before they can be executed.

Specifying a .cpp file as the type of a node element in a .launch file will not work.

project(dijkstra)    
...
add_executable(${PROJECT_NAME} src/algorithm_1.cpp)

dijkstra.cpp is the source file, not the name of the binary (ie: the compiled program). That would be dijkstra.

If you remove the .cpp from the type attribute of the node element in your .launch file, things will probably start working (assuming the rest of the .launch file is correct).

edit flag offensive delete link more
1

answered 2019-12-13 13:57:20 -0600

mbd gravatar image

updated 2019-12-13 14:14:22 -0600

Change name of your main source code file algorithm_1.cpp to dijkstra.cpp. Use the same name for both executable and source file which is a convention used by many people. Although they don't have to be same as you can see here. So try this:

...
add_executable(dijkstra src/dijkstra.cpp)

target_link_libraries(dijkstra
${catkin_LIBRARIES}
)
...

Compile your workspace, source your .bashrc and you're good to go.

Also check the CMakeLists.txt given here for other mistakes if you're still unable to run your node.

edit flag offensive delete link more

Comments

I did this however, there is still an error. I ran source ~/.bashrc and catkin_make before this. Also, the package name in Package.xml is dijkstra so I really don't know what to do. rosrun dijkstra dijkstra [rospack] Error: package 'dijkstra' not found

Parth2851 gravatar imageParth2851 ( 2019-12-14 02:04:03 -0600 )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-12-13 13:29:45 -0600

Seen: 58 times

Last updated: Dec 15 '19