在同一个项目中包含 <termios.h> 和 <asm/termios.h>

bil*_*ial 5 c++ linux header-files termios

我想什么来实现的:我想要一套定制的baud rate一些价值观tty*UART-mapped终端。

如何:我发现迄今唯一的办法就是使用struct termios2它位于结构<asm/termios>标题(如提到这里,第一个答案)。

到目前为止,我的解决方案效果很好,但现在我需要使用一些功能:

speed_t cfgetispeed(const struct termios *);
int     tcdrain(int);
int     tcflow(int, int);
int     tcflush(int, int);
int     tcgetattr(int, struct termios *);
pid_t   tcgetsid(int);
int     tcsendbreak(int, int);
int     tcsetattr(int, int, struct termios *);
Run Code Online (Sandbox Code Playgroud)

问题是<asm/termios.h>没有这样的功能,我需要包括<termios.h>才能使用它们。

问题:如果我同时包含头文件(<asm/termios.h><termios.h>),编译器会抱怨函数和结构重新声明,他是对的。

如何在不使用一些晦涩的做法的情况下解决这个问题(例如将标题之一包装在命名空间中,就像这里提到的那样)?

Arm*_*ali 6

如何在不使用一些晦涩的做法(例如将标头之一包装在命名空间中,如此处提到的)的情况下解决这个问题

如果您发现命名空间晦涩难懂,我不知道您会如何称呼它:

#define termios asmtermios
#include <asm/termios.h>
#undef  termios
#include <termios.h>
Run Code Online (Sandbox Code Playgroud)

不管怎样,这也能让你摆脱error: redefinition of 'struct termios'.