1

The following code works on linux:

include <termios.h>

using namespace std;
static struct termios old_terminal_settings;

void setterm() {
  tcgetattr(STDIN_FILENO, &old_terminal_settings);

  // Set terminal to unbuffered input mode
  struct termios new_terminal_settings = old_terminal_settings;
  new_terminal_settings.c_lflag &= ~ICANON;
  tcsetattr(STDIN_FILENO, TCSANOW, &new_terminal_settings);
}

void resetterm() {
  // Restore the original terminal settings
  tcsetattr(STDIN_FILENO, TCSANOW, &old_terminal_settings);

}

int main() {
  int c;
    setterm();
  while (c = getc(stdin)) {
    putc(c, stdout);
  }
    resetterm();
  return 0;
}

When compiled under msys2 with:

g++ -g -I/usr/include term.cc

it fails to link. I can't find any library with the missing symbols:

tcgetattr
tcsetattr

I tried:

nm /usr/lib/*.a | grep tcgetattr
nm /mingw64/lib/*.s | grep tcsetattr

Since there is an include file termios.h I assume there must be a library with the corresponding symbols? If so, how?
If not, is there anything else I can do?

I found a symbol containing the name _nc_term_tcgetattr and tcsetattr in libncurses.a in /mingw64/lib but it's only part of the curses package. Presumably to use it I would have to use curses.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Dov
  • 8,000
  • 8
  • 46
  • 75

0 Answers0