ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Cmake linking problem against serial library

asked 2016-01-25 10:58:26 -0600

Piachnp gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-01-25 12:30:34 -0600

William gravatar image

You link your probe_test target against the catkin_LIBRARIES (which contains the shared libraries for serial), but not your libProbe. Add this line:

target_link_libraries(Probe ${catkin_LIBRARIES})
edit flag offensive delete link more

Comments

Wow, that was dumb of me, thank you very much! It's working now :)

Piachnp gravatar image Piachnp  ( 2016-01-25 12:47:53 -0600 )edit

Question Tools

Stats

Asked: 2016-01-25 10:58:26 -0600

Seen: 1,714 times

Last updated: Jan 25 '16