basil
basil

Reputation: 720

LibSerial: cannot access SerialStream member functions

I am trying to do basic port programming, and it was suggested to me that I take a look at LibSerial.

I built and installed the package, but I am having issues accessing any SerialStream member functions

e.g. the following code (ls_ex.cpp) fails:

#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;
}

I am compiling it as so:

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

When I compile, I get the following error:

ls_ex.cpp: In function ‘int main(int, char**)’: ls_ex.cpp:45:15: error: ‘class LibSerial::SerialStream’ has no member named ‘isOpen’

I assume I am compiling it wrong because its easy enough to look at the code and see that isOpen() is indeed public. Also, why am I even able to instantiate SerialStream just fine but the compiler blows up when I try to call any member function?

Upvotes: 0

Views: 1371

Answers (1)

Claudiordgz
Claudiordgz

Reputation: 3049

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

Upvotes: 2

Related Questions