ncurses 编译:'stdscr'/lib64/libtinfo.so.6: 添加符号时出错

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

我正在尝试使用 ncurses 编译任何东西,但我遇到了某种链接错误。为什么?预先感谢您的帮助。

#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

找到答案:undefined reference to `stdscr'

我在使用 Centos 6.2 上的 ncurses 程序时遇到了这个问题。结果发现,ncurses有时会被拆分成两个库,ncursestinfo。在我的例子中,stdscr 存在于 libtinfo 中,而不存在于 libncurses 中,因此将 -ltinfo 添加到 link 行,在 -lncurses 之后,解决了问题。