链接C ++ - 未定义的引用

时间:2018-01-15 13:07:42

标签: compilation c++ linker boost

我尝试从http://www.webalice.it/fede.tft/serial_port/serial_port.html

编译BufferedAsyncSerial.cc

但是当我把:

g++ -lboost_system -pthread -Wall BufferedAsyncSerial.cc -o BufferedAsyncSerial

我收到错误:

 /tmp/ccrgsd5L.o: In function `main':
 BufferedAsyncSerial.cc:(.text+0x9c): undefined reference to    
`BufferedAsyncSerial::BufferedAsyncSerial(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, 
boost::asio::serial_port_base::parity, 
boost::asio::serial_port_base::character_size, 
boost::asio::serial_port_base::flow_control, 
boost::asio::serial_port_base::stop_bits)'
BufferedAsyncSerial.cc:(.text+0xe8): undefined reference to 
`AsyncSerial::writeString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
BufferedAsyncSerial.cc:(.text+0x150): undefined reference to 
`BufferedAsyncSerial::readStringUntil(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
 BufferedAsyncSerial.cc:(.text+0x1a0): undefined reference to `AsyncSerial::close()'
 BufferedAsyncSerial.cc:(.text+0x1ac): undefined reference to 
`BufferedAsyncSerial::~BufferedAsyncSerial()'
 BufferedAsyncSerial.cc:(.text+0x27c): undefined reference to `BufferedAsyncSerial::~BufferedAsyncSerial()'
 /tmp/ccrgsd5L.o: In function `boost::this_thread::sleep(boost::posix_time::ptime const&)':
 BufferedAsyncSerial.cc:(.text._ZN5boost11this_thread5sleepERKNS_10posix_time5ptimeE[_ZN5boost11this_thread5sleepERKNS_10posix_time5ptimeE]+0x28): undefined reference to 
 `boost::this_thread::hidden::sleep_until(timespec const&)'
 collect2: error: ld returned 1 exit status

我仅在BufferedAsyncSerial.h引用#include "AsyncSerial.h"中添加了BufferedAsyncSerial.cc中的引用,从#include "AsyncSerial.h"更改为#include "BufferedAsyncSerial.h"

任何人都知道如何修复它?

0 个答案:

没有答案