How to properly compile an ncurses C program with gcc

I g0t the following error when compiling the basic ncurses tutorial program from here:

#gcc ncur.c -o ncur
/tmp/ccgxJG8O.o: In function `main':
ncur.c:(.text+0x10): undefined reference to `initscr'
ncur.c:(.text+0x15): undefined reference to `cbreak'
ncur.c:(.text+0x1c): undefined reference to `stdscr'
ncur.c:(.text+0x29): undefined reference to `keypad'
ncur.c:(.text+0x3d): undefined reference to `LINES'
ncur.c:(.text+0x52): undefined reference to `COLS'
ncur.c:(.text+0x70): undefined reference to `printw'
ncur.c:(.text+0x77): undefined reference to `stdscr'
ncur.c:(.text+0x7f): undefined reference to `wrefresh'
ncur.c:(.text+0x179): undefined reference to `stdscr'
ncur.c:(.text+0x181): undefined reference to `wgetch'
ncur.c:(.text+0x196): undefined reference to `endwin'
/tmp/ccgxJG8O.o: In function `create_newwin':
ncur.c:(.text+0x1c4): undefined reference to `newwin'
ncur.c:(.text+0x209): undefined reference to `wborder'
ncur.c:(.text+0x215): undefined reference to `wrefresh'
/tmp/ccgxJG8O.o: In function `destroy_win':
ncur.c:(.text+0x268): undefined reference to `wborder'
ncur.c:(.text+0x274): undefined reference to `wrefresh'
ncur.c:(.text+0x280): undefined reference to `delwin'
collect2: error: ld returned 1 exit status

Solution: You need to link against the ncurses library:

#gcc ncur.c -o ncur -lncurses
#