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

fxk*_*ait 0 c ncurses

我正在尝试使用 编译任何内容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
Run Code Online (Sandbox Code Playgroud)

fxk*_*ait 6

找到答案:对“stdscr”的未定义引用

我在 Centos 6.2 上的 ncurses 程序中遇到了这个问题。事实证明, ncurses 有时分为两个库:ncursestinfo。就我而言,stdscr存在于libtinfo,而不是存在于libncurses,因此-ltinfo在之后添加到链接行,-lncurses解决了问题。