Search code examples
cncurses

ncurses compiling: 'stdscr'/lib64/libtinfo.so.6: error adding symbol


I'm trying to compile anything using ncurses and I have some sort of linking error. Why? Thanks in advance for your help.

#include <stdlib.h>
#include <ncurses.h>

int main(void)
{
    initscr();
    printw("Hello World!!");
    refresh();
    getch();
    endwin();

    return 0;
}

lore% gcc -o helloworld helloworld.c  -lncurses
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cc37p6Qp.o: un
defined reference to symbol 'stdscr' /lib64/libtinfo.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Solution

  • Found Answer: undefined reference to `stdscr'

    I was having this problem with an ncurses program on Centos 6.2. It turns out that ncurses is sometimes split into two libraries, ncurses and tinfo. In my case, stdscr exists in libtinfo, not in libncurses, so adding -ltinfo to the link line, after -lncurses, solved the problem.