[英]libserial undefined reference to symbol
I compiled libserial-0.6.0rc2 from source in Ubuntu 16.04 and am now trying to compile a simple test program: 我从Ubuntu 16.04的源代码编译了libserial-0.6.0rc2,现在正尝试编译一个简单的测试程序:
#include <SerialStream.h>
#include <iostream>
using namespace LibSerial;
int main(int argc, char** argv)
{
SerialStream serial_port;
serial_port.Open("/dev/ttyS0");
serial_port.SetBaudRate( SerialStreamBuf::BAUD_9600 );
serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 );
serial_port.SetParity( SerialStreamBuf::PARITY_EVEN );
serial_port.SetNumOfStopBits(1);
serial_port.write( "s", 1 ) ;
}
I'm getting the following error: 我收到以下错误:
karl@karl-T430u:~/scan/arduino$ gcc *.cpp -Wl,-
rpath -Wl,/usr/local/lib -L/usr/local/lib -lserial
/usr/bin/ld: /tmp/ccT3ucCm.o: undefined reference to symbol
'_ZNSaIcED1Ev@@GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO
missing from command line
collect2: error: ld returned 1 exit status
It took me a while to compile libserial as there was apparently a required dependency on SIP which I didn't know about. 我花了一些时间来编译libserial,因为显然需要对SIP的依赖,而我对此并不了解。 I can build the examples using the provided makefile but I am not able to build my own examples with the installed libraries.
我可以使用提供的makefile来构建示例,但无法使用已安装的库来构建自己的示例。 Does anyone have any ideas?
有人有什么想法吗?
You are attempting to compile and link a C++ program with the C compiler driver gcc
. 您正在尝试使用C编译器驱动程序
gcc
编译和链接C ++程序。 C and C++ are different languages. C和C ++是不同的语言。
gcc
does not by default link the Standard C++ library, libstdc++
, so you have an undefined reference error to a symbol _ZNSaIcED1Ev
(demangled = std::allocator<char>::~allocator()
) that is defined in that library. 默认情况下,
gcc
不会链接标准C ++库libstdc++
,因此您对该库中定义的符号_ZNSaIcED1Ev
(demangled = std::allocator<char>::~allocator()
)有未定义的引用错误。
To compile and link C++ programs use the C++ compiler driver, g++
. 要编译和链接C ++程序,请使用C ++编译器驱动程序
g++
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.