There is the following code written in C:

#include <stdio.h> #include <ncurses.h> char *buttns[] = {"New game", "Settings", "Exit"}; int counter = 0; void update(){ erase(); for(int d = 0; d < 3; d++){ if(d == counter){ attron(A_BOLD); attron(COLOR_PAIR(1)); printw("$s\n", buttns[d]); attroff(A_BOLD); attroff(COLOR_PAIR(1)); }else{ attron(COLOR_PAIR(2)); printw("%s\n", buttns[d]); attroff(COLOR_PAIR(2)); } } } int main(){ initscr(); start_color(); keypad(stdscr, TRUE); noecho(); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_WHITE, COLOR_BLACK); int ch = 0; while(ch != 'q'){ update(); } return 0; } 

However, when running the gcc Source.c command, it throws this Exception, and as I understand the trace:

/tmp/ccKQq01a.o: In function update': Source.c:(.text+0xb): undefined reference to stdscr' Source.c :(. text + 0x13): undefined reference to werase' Source.c:(.text+0x35): undefined reference to stdscr 'Source.c :(. text + 0x47): undefined reference to wattr_on' Source.c:(.text+0x4e): undefined reference to stdscr 'Source.c :(. text + 0x60): undefined reference to wattr_on' Source.c:(.text+0x7f): undefined reference to printw' Source.c :(. Text + 0x86): undefined reference to stdscr' Source.c:(.text+0x98): undefined reference to wattr_off 'Source.c :(. text + 0x9f): undefined reference to stdscr' Source.c:(.text+0xb1): undefined reference to wattr_off 'Source.c :(. text + 0xba): undefined reference to stdscr' Source.c:(.text+0xcc): undefined reference to wattr_on' Source.c :(. text + 0xeb): undefined reference to printw' Source.c:(.text+0xf2): undefined reference to stdscr 'Source.c :(. text + 0x104): undefined reference to wattr_off' /tmp/ccKQq01a.o: In function main ': Source.c :(. text + 0x122): undefined reference to initscr' Source.c:(.text+0x127): undefined reference to start_color' Source.c :(. text + 0x12e): undefined reference to stdscr' Source.c:(.text+0x13b): undefined reference to keypad' Source.c :(. Text + 0x140): undefined reference to noecho' Source.c:(.text+0x154): undefined reference to init_pair' Source.c :(. Text + 0x168): undefined reference to `init_pair 'collect2 : error: ld returned 1 exit status

How to fix?

  • This means that your project does not see the library in which these functions are defined. - Vlad from Moscow
  • Compile with the required libraries. In this case - gcc tc -lncurses - avp
  • @avp Thanks, compiled, but now does not display the "Menu". - Razor
  • Curses actually displays characters on the screen not immediately, but after a call, for example, refresh() (I already described this in some answer here). Insert at the end of your update() { ... call refresh(); . Only you still have the program looping endlessly, but it does not read (does not change) the variable ch . And in general, google the curses tutorial link and read ... - avp
  • @avp Thank you so much! I want to do graduation work for the HTP, so I started learning the console graphics, well, and the last question, maybe you know some way to work with windows on C, like javax.swing in java? - Razor

0