0
$\begingroup$

Rosanswers logo

New to CMake and trying to figure out how to include a cpp file that an executable file links to. Trying to program Object Oriented. I want to add a robot.cpp as a class file, so that i will be able to create a Robot object in my executable file.

The robot.cpp file at this location: include/manuscriptBuilder/robot.cpp

Made these modifications to the CMakeLists.txt:

  • under find_package i added:
    "robot"
  • under catkin_package i added:
    "DEPENDS robot"
  • include_directories( include ${catkin_INCLUDE_DIRS}) - add_library(robot include/manuscriptBuilder/robot.cpp) - target_link_libraries(motor_command_pub_test_node ${catkin_LIBRARIES})

Enden up with this error message:

CMake Warning at /opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake:76 (find_package):

Could not find a package configuration file provided by "robot" with any of the following names:

robotConfig.cmake
robot-config.cmake

Add the installation prefix of "robot" to CMAKE_PREFIX_PATH or set "robot_DIR" to a directory containing one of the above files. If "robot" provides a separate development package or SDK, be sure it has been installed.

Call Stack (most recent call first):

ev3_ros/CMakeLists.txt:10 (find_package)

-- Could not find the required component 'robot'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.

CMake Error at /opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake:83 (find_package):

Could not find a package configuration file provided by "robot" with any of the following names:

robotConfig.cmake
robot-config.cmake

Add the installation prefix of "robot" to CMAKE_PREFIX_PATH or set "robot_DIR" to a directory containing one of the above files. If "robot" provides a separate development package or SDK, be sure it has been installed.

Call Stack (most recent call first):

ev3_ros/CMakeLists.txt:10 (find_package)

-- Configuring incomplete, errors occurred!

As i said i am new to CMake and catkin and C++ all together, so any tutorials to understand the CMakeLists.txt file and how to use it in relation to ROS would make me very happy.


Originally posted by MadsFox on ROS Answers with karma: 11 on 2017-11-15

Post score: 1


Original comments

Comment by MadsFox on 2017-11-15:
It has worked in another project, where i had a header file and a cpp file, with the same name. I just used add_library, added it as a dependence and required component.

Comment by clyde on 2017-11-15:
Please provide the entire CMakeLists.txt file -- that will make it easier to debug. (Remove the boilerplate comments.)

Comment by clyde on 2017-11-15:
As an aside, the typical layout is this:

~/catkin_ws/src/manuscriptBuilder/robot.cpp
~/catkin_ws/src/manuscriptBuilder/include/manuscriptBuilder/robot.h

If you follow this layout the tutorials will make more sense.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

find_package is for finding existing cmake packages, not the current project. Do not include 'robot' to find_package. same with Depends - these are the packages that your package is dependent on.

You need to create a library first and then link it to your executable. Assuming your sources for robot are stored in variable SOURCES and those of the executable are stored in NODE_SOURCES, the following snippet should do the trick. you can replace those variables with your source files.

add_library(robot ${SOURCES})
target_link_libraries(robot ${catkin_LIBRARIES})

add_executable(robot_node ${NODE_SOURCES})
target_link_libraries(robot_node  ${catkin_LIBRARIES} robot)

Originally posted by ninja777 with karma: 101 on 2017-11-15

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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