0
$\begingroup$

Rosanswers logo

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

Originally posted by Parth2851 on ROS Answers with karma: 63 on 2019-12-13

Post score: 1


Original comments

Comment by gvdhoorn on 2019-12-15:
@rubicks: it would also have worked if you would've updated your answer.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by mbd with karma: 13 on 2019-12-13

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Parth2851 on 2019-12-14:
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

$\endgroup$
0
$\begingroup$

Rosanswers logo

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).


Originally posted by gvdhoorn with karma: 86574 on 2019-12-15

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.