I have an old ROS Fuerte project which code i wanted to reuse in an another ROS Hydro node, this code uses libserial library. I have a problem to find out the correct way to include this library into my new node via CMakeList.txt
Here what i include in my header:
#include <SerialStream.h>
using namespace LibSerial;
SerialStream fd;
I'm not totally sure where the error comes from but doesn't the "undefined reference" mean that problem could be within the compiling and linking?
Here is the error code:
####
#### Running command: "make cmake_check_build_system" in "/home/x/Dropbox/catkin_ws/build"
####
####
#### Running command: "make -j2 -l2" in "/home/x/Dropbox/catkin_ws/build"
####
[ 0%] [ 0%] Built target std_msgs_generate_messages_cpp
Built target std_msgs_generate_messages_py
[ 20%] [ 20%] Built target std_msgs_generate_messages_lisp
Built target serial_interface_generate_messages_cpp
[ 60%] [ 80%] Built target serial_interface_generate_messages_py
Built target serial_interface_generate_messages_lisp
[ 80%] Built target serial_interface_generate_messages
Linking CXX executable /home/x/Dropbox/catkin_ws/devel/lib/serial_interface/serial_interface
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o: In function `CA::RoverInterface::RoverInterface(ros::NodeHandle)':
serial_interface.cpp:(.text+0x514): undefined reference to `LibSerial::SerialStream::Open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Ios_Openmode)'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x48): undefined reference to `LibSerial::SerialStreamBuf::showmanyc()'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x50): undefined reference to `LibSerial::SerialStreamBuf::xsgetn(char*, long)'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x58): undefined reference to `LibSerial::SerialStreamBuf::underflow()'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x68): undefined reference to `LibSerial::SerialStreamBuf::pbackfail(int)'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x70): undefined reference to `LibSerial::SerialStreamBuf::xsputn(char const*, long)'
CMakeFiles/serial_interface.dir/src/serial_interface.cpp.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x78): undefined reference to `LibSerial::SerialStreamBuf::overflow(int)'
collect2: ld returned 1 exit status
make[2]: *** [/home/x/Dropbox/catkin_ws/devel/lib/serial_interface/serial_interface] Error 1
make[1]: *** [serial_interface/CMakeFiles/serial_interface.dir/all] Error 2
make: *** [all] Error 2
EDIT 1:
I have updated my CMakeList.txt
file to be as follows with the new information I got from an answer:
cmake_minimum_required(VERSION 2.8.3)
project(serial_interface)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
include_directories(include ${catkin_INCLUDE_DIRS})
add_message_files(
FILES
Control.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
)
add_executable(serial_interface src/serial_interface.cpp)
add_dependencies(serial_interface serial_interface_generate_messages_cpp)
target_link_libraries(serial_interface
${catkin_LIBRARIES}
libserial0
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
And if i run dpkg -L libserial0
I do get the following:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libserial0
/usr/share/doc/libserial0/copyright
/usr/share/doc/libserial0/changelog.Debian.gz
/usr/lib
/usr/lib/libserial.so.0.0.0
/usr/lib/libserial.so.0
Therefore I should have the correct library installed on my system? Anyway i still receive this error while trying to run catkin_make
.
####
#### Running command: "make cmake_check_build_system" in "/home/x/Dropbox/catkin_ws/build"
####
####
#### Running command: "make -j2 -l2" in "/home/x/Dropbox/catkin_ws/build"
####
[ 0%] [ 0%] Built target std_msgs_generate_messages_cpp
Built target std_msgs_generate_messages_py
[ 0%] [ 20%] Built target std_msgs_generate_messages_lisp
Built target serial_interface_generate_messages_cpp
[ 40%] [ 80%] Built target serial_interface_generate_messages_lisp
Built target serial_interface_generate_messages_py
Linking CXX executable /home/x/Dropbox/catkin_ws/devel/lib/serial_interface/serial_interface
[ 80%] Built target serial_interface_generate_messages
/usr/bin/ld: cannot find -llibserial0
collect2: ld returned 1 exit status
make[2]: *** [/home/x/Dropbox/catkin_ws/devel/lib/serial_interface/serial_interface] Error 1
make[1]: *** [serial_interface/CMakeFiles/serial_interface.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
Originally posted by ajr_ on ROS Answers with karma: 97 on 2014-02-10
Post score: 0