cfmakeraw隐式声明错误

时间:2017-04-27 16:29:04

标签: c implicit-declaration

我正在编写多线程应用程序(作为家庭作业)。其中一个线程专门用于读取键盘按键,因此在原始模式下使用终端。但我一直在收到错误

error: implicit declaration of function ‘cfmakeraw’ [-Werror=implicit-function-declaration]
     cfmakeraw(&tio);

即使我包含 unistd.h termios.h

我使用gcc 5.4.0和-std = c99标志在Linux(xubuntu 16.04)上进行编程。代码看起来像:

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <termios.h>
#include <pthread.h>

#include "prg_serial_nonblock.h"

void set_raw(_Bool set);

int main(int argc, char *argv[]) {
    // terminal raw mode
    set_raw(true);

    // ... some thread magic ...

    set_raw(false);
    printf("\n");
}

void set_raw(_Bool set) {
    static struct termios tio, tioOld;
    tcgetattr(STDIN_FILENO, &tio);

    if (set) { // put the terminal to raw
        tioOld = tio; //backup
        cfmakeraw(&tio);
        tio.c_lflag &= ~ECHO; // assure echo is disabled
        tcsetattr(STDIN_FILENO, TCSANOW, &tio);
    }
    else {      // set the previous settingsreset
        tcsetattr(STDIN_FILENO, TCSANOW, &tioOld);
    }
}

1 个答案:

答案 0 :(得分:0)

正如manpage所说,

  

glibc的功能测试宏要求(参见feature_test_macros(7)):

     

cfsetspeed (), cfmakeraw ():
  由于glibc 2.19:
  int main ( void ) { test a; a.Add(1,5) . Add( 4, 8); a.print(); return 0; }
  Glibc 2.19及更早版本:
  _DEFAULT_SOURCE

因此,您应该在命令行中添加_BSD_SOURCE,或者在任何系统-D_BSD_SOURCE -D_DEFAULT_SOURCE之前添加#define _BSD_SOURCE#define _DEFAULT_SOURCE

相关问题