0

我正在尝试进行基本的端口编程,有人建议我看看 LibSerial。

我构建并安装了包,但在访问任何 SerialStream 成员函数时遇到问题

例如,以下代码 (ls_ex.cpp) 失败:

#include <SerialStream.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cerrno>
using namespace std;
using namespace LibSerial;

int main(int count, char* parms[])
{
    if (count != 2)
        exit(1);

    //open port
    string fname = parms[1];
    SerialStream port(fname);
    cout << port.isOpen() << endl;
    port.Close();

    return 0;
}

我正在编译它:

g++ -o ls_ex ls_ex.cpp /usr/local/lib/libserial.a /usr/local/lib/libserial.so

当我编译时,我收到以下错误:

ls_ex.cpp: In function 'int main(int, char**)': ls_ex.cpp:45:15: error: 'class LibSerial::SerialStream' has no member named 'isOpen'</p>

我假设我编译错了,因为它很容易查看代码并看到 isOpen() 确实是公开的。另外,为什么我什至能够很好地实例化 SerialStream 但是当我尝试调用任何成员函数时编译器会崩溃?

4

1 回答 1

2

It is like this

g++ -o ls_ex ls_ex.cpp -lserial -L/usr/local/lib/

If you want the .a to be used instead of .so

g++ -o ls_ex ls_ex.cpp -static -lserial -L/usr/local/lib/

Be sure to specify your includes to your SerialStream.h as well

 g++ -o ls_ex ls_ex.cpp -static -lserial -L/usr/local/lib/ -I/path/to/SerialStream
于 2014-03-14T21:31:55.210 回答