Robotics StackExchange | Archived questions

Ros2 Foxy unable to colcon build, when added custom made hpp files.

Hello everyone, I tried to make my own publisher/subscriber package, which will have bumpandgo behavior. Whenever i tried to include a headerfile to my build, colcon fails to build. I cannot post pictures so here is the error and the cmake file,

#ERROR
> /home/stag/bookros2_ws/src/exercises/src/bumpgo/bumpgo_node.cpp:1:10: fatal error: include/bumpgo/bumpgo_node.hpp: No such file or directory
    1 | #include "include/bumpgo/bumpgo_node.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/bumpgo.dir/build.make:63: CMakeFiles/bumpgo.dir/src/bumpgo/bumpgo_node.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/home/stag/bookros2_ws/src/exercises/src/bumpgo_main.cpp:1:10: fatal error: include/bumpgo/bumpgo_node.hpp: No such file or directory
    1 | #include "include/bumpgo/bumpgo_node.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

CMAKE FILE

> cmake_minimum_required(VERSION 3.5)
project(exercises)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)


set(dependencies
    rclcpp
    sensor_msgs
    geometry_msgs
)
include_directories(include)


add_executable(bumpgo
   src/bumpgo/bumpgo_node.cpp
   src/bumpgo_main.cpp
)
ament_target_dependencies(bumpgo ${dependencies})


install(TARGETS
  bumpgo
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}

)

include_directories(include)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()

  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_dependencies(${dependencies})
ament_package()

CPP FILE WHICH ADDS HPP FILE

include "include/bumpgo/bumpgo_node.hpp"
include "sensor_msgs/msg/laser_scan.hpp"
include "geometry_msgs/msg/twist.hpp"


BumpGoNode::BumpGoNode():Node("bump_go"){
        subscribed_scan = create_subscription<sensor_msgs::msg::LaserScan>("input_scan",rclcpp::SensorDataQoS(),
        std::bind(&BumpGoNode::scan_callback,this));
        published_twist = create_publisher<geometry_msgs::msg::Twist>("output_vel",10);
    } 
    void BumpGoNode::scan_callback(sensor_msgs::msg::LaserScan::UniquePtr msg){
        last_scan = std::move(msg);
    }

HPP FILE

include "sensor_msgs/msg/laser_scan.hpp"
include "geometry_msgs/msg/twist.hpp"
include "rclcpp/rclcpp.hpp"

class BumpGoNode: public rclcpp::Node{
    private:
        rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr subscribed_scan;
        rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr published_twist;
        void scan_callback(sensor_msgs::msg::LaserScan::UniquePtr scan_msg);
        sensor_msgs::msg::LaserScan::UniquePtr last_scan;
    public:
        BumpGoNode();
};

Location of the files

CPP file is in exercises/src/bumpgo/bumpgo_main.cpp

Header file is in exercises/include/bumpgo/bumpgo/bumpgo_node.hpp

Asked by Stag on 2022-12-05 10:41:19 UTC

Comments

Hi, you can try to simply use <package-name>/<header-file-name.hpp> format for including custom header files. For your case it should then be : #include "exercises/bumpgo_node.hpp . The build system should take care of the rest.

Asked by sampreets3 on 2022-12-06 08:09:35 UTC

Hello, thanks for the answer. Tried but didn't work.

Asked by Stag on 2022-12-10 02:41:29 UTC

Answers