Termios and rootcint

Hi there,

I’m writing code to handle serial communications. This code must be part of the rest of our data acquisition software which relies on CINT. I am able to compile my code in g++, but I am not able to compile the Cint.cc file made by rootcint.

Here is a shortened version of the serial comm. class called RS232.hh

[code]#ifndef RS232_HH
#define RS232_HH

#include
#include <termios.h>
#include “TNamed.h”

using std::string;

typedef int SerialHandle;

class RS232 : public TNamed {

public:
// Ctors
RS232();

static SerialHandle Open(string device);
static int SetBaudRate(struct termios *rs232_attr, long baudrate);
static int Close(SerialHandle rs232);

private:
ClassDef(RS232,1)
};

#endif[/code]
The problem comes about in the SetBaudRate prototype, which uses the termios structure that is defined in termios.h (in /usr/include/bits).

Here is the associated RS232.cc file

[code]#include “RS232.hh”
#include
#include <fcntl.h>

using std::cout;
using std::endl;
using std::string;

ClassImp(RS232)

RS232::RS232() {}

SerialHandle RS232::Open(string device)
{
SerialHandle rs232;
rs232 = open(device.c_str(), O_RDWR | O_NOCTTY);
return rs232;
}

int RS232::SetBaudRate(struct termios *rs232_attr, long baudrate)
{
switch (baudrate) {
case 19200:
rs232_attr->c_cflag |= B19200; break;
default:
cout << “unsupported baud rate” << endl;
return -1;
}
return 0;
}

int RS232::Close(SerialHandle rs232)
{
close(rs232);
return true;
}[/code]
When I compile, I get the following:

g++ -O -Wall -fPIC -DDM_DAQ -I/usr/local/lib -I/usr/include/cfitsio -I/usr/local/include -pthread -m32 -I/usr/local/cern/root/include -c RS232.cc Generating dictionary ... /usr/local/cern/root/bin/rootcint -f RS232Cint.cc -c -p RS232.hh Compiling... g++ -O -Wall -fPIC -DDM_DAQ -I/usr/local/lib -I/usr/include/cfitsio -I/usr/local/include -pthread -m32 -I/usr/local/cern/root/include -c RS232Cint.cc RS232Cint.cc: In function ‘int G__RS232Cint_183_0_3(G__value*, const char*, G__param*, int)’: RS232Cint.cc:215: error: ‘termios’ is not a member of ‘RS232’ RS232Cint.cc:215: error: expected primary-expression before ‘long’ RS232Cint.cc:215: error: expected `)' before ‘long’ RS232Cint.cc: In function ‘void G__setup_memfuncRS232()’: RS232Cint.cc:475: error: expected primary-expression before ‘void’ RS232Cint.cc:475: error: expected `)' before ‘void’
The relevant block of code from RS232Cint.cc is:

static int G__RS232Cint_183_0_3(G__value* result7, G__CONST char* funcname, struct G__param* libp,\ int hash) { G__letint(result7, 105, (long) RS232::SetBaudRate((RS232::termios*) G__int(libp->para[0]), (\ long) G__int(libp->para[1]))); return(1 || funcname || hash || result7 || libp) ; }
and so rootcint seems to have associated termios with RS232, not with the external include file termios.h.

Any help on how to use the termios structure that is defined in an external file (in the standard include location) would be greatly appreciated! I’ve had similar issues before, but have just worked around them in awkward ways. But I’d like to know how to do this properly, without forcing myself to omit the termios structure from the class declaration file (RS232.hh).

Many thanks in advance for your help,
James

Hi,

Try using#ifndef __CINT__ #include <termios.h> #else struct termios; #endif

Cheers,
Philippe.

Hi Phillipe,

Your suggestion worked. Is there a place where I could read more about the solution and why it works?

Thank you very much,
James

Hi,

In the CINT documentation :slight_smile:. It works because CINT is not able to properly parse termios.h and the #ifndef replaces the parsing of termios.h by a (drastic) simplification that is sufficient for dictionary generation.

Cheers,
Philippe.