Calling ros library

asked 2021-01-19 04:11:57 -0500

feryop gravatar image

I am newbie in ROS and I doing a simple example to learn but it is not compile. I have a workspace with 2 packages: "ros_utils" and "ros_main". "ros_utils should print a message from "ros_main".

"ros_utils":

  • class Console.cpp

    #include <ros_utils console.h="">

    namespace ros_utils
    {
        int ROS_PRINT()
        {
            printf ("ROS PRINT");
            return 0;
        }
    }
    
  • Cmakelists.txt

    cmake_minimum_required(VERSION 3.0.2) project(ros_utils)

    find_package( catkin REQUIRED COMPONENTS roscpp )
    
    catkin_package( INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME}
      CATKIN_DEPENDS roscpp
    )
    
    include_directories( include ${catkin_INCLUDE_DIRS} )
    
    add_library( ${PROJECT_NAME} src/Console.cpp )
    
    target_link_libraries( ${PROJECT_NAME} )
    

"ros_main"

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <ros_utils/Console.h>


int main(int argc, char *argv[])
{
    printf("Hello world\n");


    ros_utils::ROS_PRINT();

}
  • CMakeLists.txt

    find_package( catkin REQUIRED COMPONENTS roscpp ros_utils )

    catkin_package( INCLUDE_DIRS include LIBRARIES ${PROJECT_NAME} CATKIN_DEPENDS roscpp )

    include_directories( include ${catkin_INCLUDE_DIRS} )

    add_executable(main2 src/main2.cpp) target_link_libraries(main2 ${catkin_LIBRARIES})

  • package.xml

    <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>ros_utils</build_depend>

    <exec_depend>ros_utils</exec_depend>

    <exec_depend>roscpp</exec_depend>

When I run catkin_make, terminal shows "/home/ubuntu/catkin_ws/src/ros_main/src/main2.cpp:14:2: error: ‘ros_utils’ has not been declared 14 | ros_utils::ROS_PRINT();"

Do you know how I can to call to this library?

Thank you very much.

edit retag flag offensive close merge delete

Comments

it is Console.h or console.h? (i think you wrote console.h in Console.cpp) Can you show us Console.h?

Solrac3589 gravatar image Solrac3589  ( 2021-01-20 04:00:55 -0500 )edit