gpt4 book ai didi

c++ - 在同一项目中包含

转载 作者:IT王子 更新时间:2023-10-29 00:33:37 32 4
gpt4 key购买 nike

我想要实现的目标:我想设置自定义 baud rate一些值 tty* -喜欢UART -映射终端。

方法:目前我发现的唯一方法是使用 struct termios2结构位于<asm/termios> header (如前所述 here ,第一个答案)。

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

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 *);

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

问题:如果我同时包含两个 header (<asm/termios.h><termios.h>),编译器会尖叫函数和结构重新声明,他是对的。

如何在不使用一些晦涩的做法的情况下解决这个问题(比如将其中一个 header 包装在命名空间中,如提到的 here )?

最佳答案

How can I solve this without using some obscure practice (like wrapping one of headers in a namespace, like mentioned here)?

如果你觉得命名空间晦涩难懂,我不知道你会怎么调用它:

#define termios asmtermios
#include <asm/termios.h>
#undef termios
#include <termios.h>

无论如何,这也可以让您摆脱错误:“struct termios”的重新定义

关于c++ - 在同一项目中包含 <termios.h> 和 <asm/termios.h>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37710525/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com