0

I have build some code using LibSerial but when i compile it i have this error messages:

/tmp/ccUpE4te.o: In function `main':
test.c:(.text+0x8d): undefined reference to `LibSerial::SerialStream::Open(std::string, std::_Ios_Openmode)'
test.c:(.text+0xbf): undefined reference to `LibSerial::SerialStream::SetBaudRate(LibSerial::SerialStreamBuf::BaudRateEnum)'
test.c:(.text+0xd3): undefined reference to `LibSerial::SerialStream::SetCharSize(LibSerial::SerialStreamBuf::CharSizeEnum)'
test.c:(.text+0xe7): undefined reference to `LibSerial::SerialStream::SetNumOfStopBits(short)'
test.c:(.text+0xfb): undefined reference to `LibSerial::SerialStream::SetFlowControl(LibSerial::SerialStreamBuf::FlowControlEnum)'
test.c:(.text+0x10f): undefined reference to `LibSerial::SerialStream::SetVTime(short)'
test.c:(.text+0x123): undefined reference to `LibSerial::SerialStream::SetVMin(short)'
test.c:(.text+0x1a1): undefined reference to `LibSerial::SerialStream::Open(std::string, std::_Ios_Openmode)'
test.c:(.text+0x1d3): undefined reference to `LibSerial::SerialStream::SetBaudRate(LibSerial::SerialStreamBuf::BaudRateEnum)'
test.c:(.text+0x1e7): undefined reference to `LibSerial::SerialStream::SetCharSize(LibSerial::SerialStreamBuf::CharSizeEnum)'
test.c:(.text+0x1fb): undefined reference to `LibSerial::SerialStream::SetNumOfStopBits(short)'
test.c:(.text+0x20f): undefined reference to `LibSerial::SerialStream::SetFlowControl(LibSerial::SerialStreamBuf::FlowControlEnum)'
test.c:(.text+0x223): undefined reference to `LibSerial::SerialStream::SetVTime(short)'
test.c:(.text+0x237): undefined reference to `LibSerial::SerialStream::SetVMin(short)'
/tmp/ccUpE4te.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[_ZTVN9LibSerial15SerialStreamBufE]+0x48): undefined reference to `LibSerial::SerialStreamBuf::showmanyc()'
/tmp/ccUpE4te.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[_ZTVN9LibSerial15SerialStreamBufE]+0x50): undefined reference to `LibSerial::SerialStreamBuf::xsgetn(char*, long)'
/tmp/ccUpE4te.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[_ZTVN9LibSerial15SerialStreamBufE]+0x58): undefined reference to `LibSerial::SerialStreamBuf::underflow()'
/tmp/ccUpE4te.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[_ZTVN9LibSerial15SerialStreamBufE]+0x68): undefined reference to `LibSerial::SerialStreamBuf::pbackfail(int)'
/tmp/ccUpE4te.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[_ZTVN9LibSerial15SerialStreamBufE]+0x70): undefined reference to `LibSerial::SerialStreamBuf::xsputn(char const*, long)'
/tmp/ccUpE4te.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[_ZTVN9LibSerial15SerialStreamBufE]+0x78): undefined reference to `LibSerial::SerialStreamBuf::overflow(int)'
collect2: error: ld returned 1 exit status

I believe that they are linking errors but i cannot understand how i can solve my problem.

4

1 回答 1

2

解决方案:“gcc -L/usr/local/lib -lserial test.c”

这个解决方案意味着什么?

gcc 不知道您要使用的库。你应该告诉他。

gcc 标志“-l”是告诉 gcc 你想链接到安装在你计算机上的库的方式。

在您的情况下,您应该指定:“-lserial”

您需要做的另一件事是让 g++ 知道在哪里可以找到这个库。

假设你没有做任何特别的事情,libaray 将在 /usr/local/lib 下找到,并将被命名为 libserial.so

您可以通过添加另一个标志“-L”(应该是 -L/usr/local/lib)来告诉 gcc 将库保存在哪里,或者您可以使用局部变量来执行此操作:

导出 LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

于 2014-11-15T11:07:17.553 回答