Ask Your Question
1

Problem with Serial library

asked 2018-01-09 09:26:35 -0600

Skained gravatar image

updated 2018-01-09 09:54:02 -0600

Hi, I have a problem when i use serial.h library, this is my test code:

#include "ros/ros.h"
#include "serial/serial.h"
#include <string>

int main(int argc, char **argv)
{
ros::init(argc, argv, "Serial");

std::string port = "/dev/ttyUSB1";
unsigned long baud = 9600;
serial::Serial myserial(port, baud, serial::Timeout(250));
if(!myserial.isOpen())
myserial.open();
size_t size = 4;
std::string read;
while (ros::ok())
{
read = myserial.read(size);
for(int x=0; x<size; x++)

{
ROS_INFO("Valores leidos: %s ", read.c_str());
ROS_INFO(" ");
}
ROS_INFO("\n");
ros::spinOnce();
}
return 0;
};

and when i compile, this is the error:

CMakeFiles/Prueba_serial.dir/src/prueba_serial.cpp.o: In the function 'main':
prueba_serial.cpp:(.text.startup+0x145): reference toserial::Serial::Serial(std::__cxx11::basic_string<char, std::char_traits, std::allocator >const&, unsigned int, serial::Timeout, serial::bytesize_t, serial::parity_t, serial::stopbits_t,serial::flowcontrol_t)' sin definirprueba_serial.cpp:(.text.startup+0x155): reference to serial::Serial::isOpen() const' not define
prueba_serial.cpp:(.text.startup+0x1c1): reference toserial::Serial::read[abi:cxx11](unsigned long)'not defineprueba_serial.cpp:(.text.startup+0x606): reference to serial::Serial::~Serial()' not define
prueba_serial.cpp:(.text.startup+0x64c): reference toserial::Serial::open()' not defineprueba_serial.cpp:(.text.startup+0x660): reference to serial::Serial::~Serial()' not define

collect2: error: ld returned 1 exit status

thanks and sorry for my English

pd: sorry for the duplicate question.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2018-01-09 09:54:18 -0600

gvdhoorn gravatar image

updated 2018-01-09 09:55:09 -0600

This tells us that most likely you forgot to add the serial package to your find_package(catkin COMPONENT ..) line in your CMakeLists.txt.

See also the Catkin documentation on adding catkin library dependencies.

Without seeing your CMakeLists.txt this is a guess though.

edit flag offensive delete link more

Comments

beat me to it :)

William gravatar imageWilliam ( 2018-01-09 09:55:16 -0600 )edit

Had to deal with the duplicate, so thought might as well answer it :)

gvdhoorn gravatar imagegvdhoorn ( 2018-01-09 09:56:48 -0600 )edit

ok.. yes, this is the problem, my fail

thank you very much

Skained gravatar imageSkained ( 2018-01-09 10:06:51 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-01-09 09:26:35 -0600

Seen: 42 times

Last updated: Jan 09 '18