【问题标题】:O_RDWR undeclared for terminal终端未声明 O_RDWR
【发布时间】:2016-03-22 03:11:27
【问题描述】:

我使用的是更新升级的ubuntu 14.0.4LTS。

我已经编写了串行通信的代码。

 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
 #include <errno.h>
 #include <sys/stat.h>
 #include <termios.h>

以上文件已包含在代码中。

当我编译代码时,它返回错误“O_RDWR undeclared” 如果我包含 fcntl.h,则编译器返回错误“参数类型 1 不兼容”,这意味着打开的函数需要 const char* 类型的参数。

struct termios TtyN;
open( TtyN, O_RDWR );

类型转换不合适。什么是正确的解决方案?

【问题讨论】:

  • 你可以尝试添加#include 然后尝试

标签: c ubuntu terminal ubuntu-14.04


【解决方案1】:

man 2 open 将显示open() 所需的头文件。即,

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

接下来我建议查看man 3 termios

【讨论】:

    【解决方案2】:

    open 采用路径字符串 (char *),而不是随机的 structstruct termios 用于specific terminal control APIs,而不是任意文件操作函数。

    也许您想open 类似"/dev/tty#"(其中# 替换为tty 号码)?

    【讨论】:

      【解决方案3】:

      open的第一个参数是char*pathname,不是struct termios类型。 不要那样打开它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-20
        • 1970-01-01
        • 1970-01-01
        • 2014-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多