ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Rosrun can not find an executable file.

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 close merge delete ## Comments @rubicks: it would also have worked if you would've updated your answer. ( 2019-12-15 12:44:46 -0600 )edit ## 2 Answers Sort by » oldest newest most voted 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).

more

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:

...

\${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.

more

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

( 2019-12-14 02:04:03 -0600 )edit