Adding header files to a node
Hello
I'm trying to add C++ header files to a ROS node but when I do catkin_make it gives the following error:
CMakeFiles/hello.dir/src/hello.cpp.o: In function `chatterCallback(boost::shared_ptr<std_msgs::String_<std::allocator<void> > const> const&)':
hello.cpp:(.text+0x13): undefined reference to `sleepms(int)'
hello.cpp:(.text+0x3b): undefined reference to `RoboteqDevice::SetCommand(int, int, int)'
hello.cpp:(.text+0xa4): undefined reference to `RoboteqDevice::Disconnect()'
CMakeFiles/hello.dir/src/hello.cpp.o: In function `main':
hello.cpp:(.text+0x201): undefined reference to `RoboteqDevice::Connect(std::string)'
CMakeFiles/hello.dir/src/hello.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
hello.cpp:(.text+0x598): undefined reference to `RoboteqDevice::RoboteqDevice()'
hello.cpp:(.text+0x5a7): undefined reference to `RoboteqDevice::~RoboteqDevice()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/nouf/catkin_ws/devel/lib/roboteq_motor/hello] Error 1
make[1]: *** [roboteq_motor/CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
The header files are under include/PKG_NAME
This is the .cpp node:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include "roboteq_motor/RoboteqDevice.h"
#include "roboteq_motor/ErrorCodes.h"
#include "roboteq_motor/Constants.h"
#include <unistd.h>
#include <ros/ros.h>
#include <std_msgs/String.h>
using namespace std;
int status;
RoboteqDevice device;
void chatterCallback( const std_msgs::String::ConstPtr& msg){
sleepms(10);
cout<<"- SetCommand(_GO, 1, 1)...";
if((status = device.SetCommand(_GO, 1, 700)) != RQ_SUCCESS)
cout<<"failed --> "<<status<<endl;
else
cout<<"succeeded."<<endl;
device.Disconnect();
}
int main(int argc, char *argv[])
{
ros::init(argc, argv, "hello");
ros::NodeHandle nh;
string response = "";
status = device.Connect("/dev/ttyACM0");
if(status != RQ_SUCCESS)
{
cout<<"Error connecting to device: "<<status<<"."<<endl;
return 1;
}
//Wait 10 ms before sending another command to device
ros::Subscriber sub = nh.subscribe("chatter", 1000, chatterCallback);
ros::spin();
return 0;
This is CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(roboteq_motor)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
)
catkin_package(
INCLUDE_DIRS include/${PROJECT_NAME}/
LIBRARIES roboteq_motor
CATKIN_DEPENDS roscpp std_msgs
DEPENDS system_lib
)
include_directories(include ${catkin_INCLUDE_DIRS})
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
add_executable(hello src/hello.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})
SOLUTION: I changed this line
add_executable(hello src/hello.cpp)
to this
add_executable(hello src/hello.cpp src/RoboteqDevice.cpp)
THANK YOU ALL
Btw: these are linker errors (missing symbols), not compiler errors (missing includes).
What are the missing symbols?
etc. Those are symbols the linker cannot find. They are not errors from the compiler.
so what do you suggest as a solution?