Hello everyone, I am having a little bit of trouble making the following work in ROS. The problem is the following:
- I am writing a library to control a probe which communicates through serial. Hence, I thought I would use this serial library: http://wiki.ros.org/serial
- The serial library was installed using $ sudo apt-get install ros-jade-serial and works correctly since another test I made used it successfully (just including it in a subscriber node that listened to a boolean msg and triggered a simple serial communication).
- rospack find serial works and outputs the following: /opt/ros/jade/share/serial
- The file structure is the following:
~/catkin_ws/src/fingertip/src/Probe.cpp
~/catkin_ws/src/fingertip/src/probe_test.cpp
~/catkin_ws/src/fingertip/include/Probe.h
Probe.h
#ifndef __PROBE_H__
#define __PROBE_H__
#include <serial/serial.h>
class Probe
{
private:
serial::Serial my_serial;
public:
Probe();
~Probe();
};
#endif
Probe.cpp
#include <iostream>
#include <string.h>
#include <Probe.h>
Probe::Probe (void)
{
my_serial.setPort("/dev/ttyUSB1");
my_serial.setBaudrate(9600);
serial::Timeout to = serial::Timeout::simpleTimeout(1000);
my_serial.setTimeout(to);
my_serial.open();
}
Probe::~Probe(void)
{
my_serial.close();
}
probe_test.cpp
#include <iostream>
#include <string.h>
#include <Probe.h>
int main(int argc, char **argv)
{
Probe my_probe; //Creat an object by using class Probe
return 0;
}
CmakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(fingertip)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
rosserial_arduino
serial
std_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS roscpp rospy rosserial_arduino serial std_msgs
DEPENDS system_lib
)
include_directories(
${catkin_INCLUDE_DIRS}
include
~/catkin_ws/src/fingertip/include
)
add_executable(probe_test src/probe_test.cpp)
add_library(Probe src/Probe.cpp)
target_link_libraries(probe_test ${catkin_LIBRARIES} Probe)
So, as you can see, a very bare bones code for now. I've read the documentation on CMake both here and here but I can't figure out why this is not working. Apparently this is not a problem of linking the library I made, but finding the serial package. This is the output of my catkin_make command:
Base path: /home/roam-lab/catkin_ws
Source space: /home/roam-lab/catkin_ws/src
Build space: /home/roam-lab/catkin_ws/build
Devel space: /home/roam-lab/catkin_ws/devel
Install space: /home/roam-lab/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/roam-lab/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/roam-lab/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/roam-lab/catkin_ws/devel;/opt/ros/jade
-- This workspace overlays: /home/roam-lab/catkin_ws/devel;/opt/ros/jade
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/roam-lab/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.16
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - fingertip
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'fingertip'
-- ==> add_subdirectory(fingertip)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/roam-lab/catkin_ws/build
####
#### Running command: "make -j8 -l8" in "/home/roam-lab/catkin_ws/build"
####
[ 50%] Built target Probe
Linking CXX executable probe_test
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::open()'
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::setBaudrate(unsigned int)'
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::Serial(std::string const&, unsigned int, serial::Timeout, serial::bytesize_t, serial::parity_t, serial::stopbits_t, serial::flowcontrol_t)'
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::close()'
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::setTimeout(serial::Timeout&)'
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::setPort(std::string const&)'
/home/roam-lab/catkin_ws/devel/lib/libProbe.so: undefined reference to `serial::Serial::~Serial()'
collect2: error: ld returned 1 exit status
make[2]: *** [fingertip/probe_test] Error 1
make[1]: *** [fingertip/CMakeFiles/probe_test.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
Any help will be very appreciated. Thanks in advance for your time!
Originally posted by Piachnp on ROS Answers with karma: 45 on 2016-01-25
Post score: 1