マルチスレッドアプリケーションを(宿題として)書いています。これらのスレッドの 1 つは、キーボード プレスの読み取り専用であるため、ターミナルを raw モードで使用します。しかし、私はエラーが発生し続けます
error: implicit declaration of function ‘cfmakeraw’ [-Werror=implicit-function-declaration]
cfmakeraw(&tio);
unistd.hとtermios.hが含まれていますが。
-std=c99 フラグを指定して gcc 5.4.0 を使用して 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);
}
}