I am working on a pseudo OS using Rust and c++, I am trying to detect the keys pressed using c++ with ncurses (I am aware that there is a similar crate for Rust) and in the build.rs I have the following code
cc::Build::new()
.cpp(true)
.file("src/button.cpp")
.flag("-lncurses") // Link with ncurses library
.compile("button.a");
But at the moment of making cargo run I get the following errors:
> undefined reference to `initscr'.
> undefined reference to `cbreak
> undefined reference to `noecho
> undefined reference to `stdscr'
> undefined reference to `keypad
> undefined reference to `stdscr'
> undefined reference to `wgetch'
> undefined reference to `printw'
The code in which the error occurs is as follows:
// This code is provided by ChatGPT for testing purposes
#include <iostream>
#include <ncurses.h>
using namespace std;
extern "C" {
void button() {
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
int key;
while (true) {
key = wgetch(stdscr);
if (key == KEY_DOWN)
printw("Arrow down");
else if (key == KEY_UP)
printw("Arrow up");
else if (key == KEY_LEFT)
printw("Arrow left");
else if (key == KEY_RIGHT)
printw("Arrow right");
else if (key == 'n')
printw("Return");
else if (key == 3)
break;
else if (key < 256)
printw("%c", key);
else
printw("Special character");
printw("n");
refresh();
}
endwin();
}
}
I am trying not to get these errors when charging run
New contributor
gonzalo silvalde blanco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1