0

I want to use some of the functionality of <termios.h and <asm/termios.h>, but they contain functions with the same name, and only including them both I got error: redefinition of 'struct termio'.

I managed to use some of <asm/termios.h structures (struct termios2) by isolating the #include directive exactly where I need (in a function).

void MyClass::MyMethod() {
#include <asm/termios.h>
    struct termios2 tio;

    // do stuff with tio variable.
}

This works fine for only one function, but if I try to do the same with more functions (including the <asm/termios.h> header) I get aggregate 'MyClass::MyMethod()::termios2 tio' has incomplete type and cannot be defined

Any solutions?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
mariusmmg2
  • 713
  • 18
  • 37
  • 2
    You should not really include headers inside functions like that. The declarations and definitions and macros inside a header should most of the time be in the global scope, which means you include the header only *once* at the top of the source file. – Some programmer dude Jun 08 '16 at 08:33
  • 2
    wrap one (or both) of them into another class, and use the wrappers – Gar Jun 08 '16 at 08:35
  • 1
    @BoBTFish I know it's bad and I don't like it, but it was the only way I got it working, and this is why I'm asking for alternatives. – mariusmmg2 Jun 08 '16 at 08:36
  • As for the `` header file, that's the one you really should be using. `` is not part of the user-space library. – Some programmer dude Jun 08 '16 at 08:38
  • @JoachimPileborg I need something from ``, can't be done without it. – mariusmmg2 Jun 08 '16 at 08:39
  • Then I think you should post another question, telling us about the *actual* problem you have, including this solution that you have tried in solving it. Please [read about the XY problem](http://xyproblem.info/). – Some programmer dude Jun 08 '16 at 08:41
  • 1
    @JoachimPileborg That is exactly his question. He just gave the code he has to demonstrate some effort. He may make more clear in the question that he does not want to go that route. – Bernhard Jun 08 '16 at 08:49
  • @JoachimPileborg There's a context-depended question: http://stackoverflow.com/questions/37710525/including-termios-h-and-asm-termios-h-in-the-same-project – mariusmmg2 Jun 08 '16 at 20:22

0 Answers0