Undefined reference to class function
Hi. Sorry for all mistakes, English is not my native language. So I migration my project to ros2 foxy, and I have following problem:
/usr/bin/ld: CMakeFiles/minicar_control_node.dir/src/control_node.cpp.o: in function `main':
control_node.cpp:(.text+0x8a4): undefined reference to `minicar::LoopbackRobotHWSim::LoopbackRobotHWSim()'
/usr/bin/ld: control_node.cpp:(.text+0xa8a): undefined reference to `minicar::STMRobotHW::STMRobotHW()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/minicar_control_node.dir/build.make:1044: minicar_control_node] Error 1
make[1]: *** [CMakeFiles/Makefile2:439: CMakeFiles/minicar_control_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:141: all] Error 2
---
Failed <<< minicar_control [10.6s, exited with code 2]
I thought that it maybe not ROS related and I made a small mistake and did not notice it, but still I failed to find it in my code or find a solution on stackoverflow. This is how those references is looked in control_node.cpp:
minicar::BaseRobotHWPtr hw;
if(ControllerType == "loopback")
{
hw.reset(new minicar::LoopbackRobotHWSim);
RCLCPP_INFO(nh->get_logger(),"Controller initialized: loopback");
}
else if(ControllerType == "stm")
{
hw.reset(new minicar::STMRobotHW);
RCLCPP_INFO(nh->get_logger(),"Controller initialized: stm");
}
else
{
RCLCPP_INFO(nh->get_logger(),"Unknown controller type!");
return 1;
}
This is constructors from header files:
class LoopbackRobotHWSim : public BaseRobotHW
{
public:
LoopbackRobotHWSim();
~LoopbackRobotHWSim();
class STMRobotHW : public BaseRobotHW, public rclcpp::Node
{
public:
STMRobotHW();
~STMRobotHW();
And constructors from cpp files:
LoopbackRobotHWSim::LoopbackRobotHWSim()
{
};
LoopbackRobotHWSim::~LoopbackRobotHWSim()
{
};
STMRobotHW::STMRobotHW() : rclcpp::Node("stm_hw_interface_node")
{
sensorPublishers[0] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/ground_front_0", 1000);
sensorPublishers[1] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/ground_front_1", 1000);
sensorPublishers[2] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/front_0", 1000);
sensorPublishers[3] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/front_1", 1000);
sensorPublishers[4] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/front_2", 1000);
sensorPublishers[5] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/front_3", 1000);
sensorPublishers[6] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/front_4", 1000);
sensorPublishers[7] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/ground_back_0", 1000);
sensorPublishers[8] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/ground_back_1", 1000);
sensorPublishers[9] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/back_0", 1000);
sensorPublishers[10] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/back_1", 1000);
sensorPublishers[11] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/back_2", 1000);
sensorPublishers[12] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/back_3", 1000);
sensorPublishers[13] = this->create_publisher<sensor_msgs::msg::Range>("minicar/sensor/back_4", 1000);
hw_feedback_sub = create_subscription<minicar_control::msg::Feedback>("hw_feedback", 1000, std::bind(&STMRobotHW::feedbackCallback, this, _1));
hw_control_pub = this->create_publisher<minicar_control::msg::Control>("hw_control", 1000);
};
STMRobotHW::~STMRobotHW()
{
delete actuatorFrontValues_rad;
delete wheelFrontLeftValues_rad;
delete wheelFrontRightValues_rad;
delete actuatorRearValues_rad;
delete wheelRearLeftValues_rad;
delete wheelRearRightValues_rad;
};
Just in case, this is CMakeLists.txt file:
cmake_minimum_required(VERSION 3.5)
project(minicar_control)
# Add support for C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
# Load catkin and all dependencies required for this package
link_directories(${catkin_LIBRARY_DIRS})
## Restrict Windows header namespace usage
if(WIN32)
add_definitions(-DNOGDI)
endif()
add_library(minicar_hw_interface src/loopback_hw_interface.cpp
src/stm_hw_interface.cpp src/base_hw_interface.cpp)
add_executable(minicar_control_node src/control_node.cpp)
add_executable(cmd_vel_limiter src/cmd_vel_limiter_node.cpp)
find_package(ament_cmake REQUIRED)
find_package(std_srvs REQUIRED)
find_package(angles REQUIRED)
find_package(controller_manager REQUIRED)
find_package(transmission_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(urdf REQUIRED)
find_package(control_toolbox REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(rosidl_default_generators REQUIRED)
set(INCLUDE_DIRS ${ament_cmake_INCLUDE_DIRS} ${angles_INCLUDE_DIRS}
${controller_manager_INCLUDE_DIRS} ${transmission_interface_INCLUDE_DIRS}
${pluginlib_INCLUDE_DIRS}
${urdf_INCLUDE_DIRS ...