首页 > 解决方案 > 如何在 Kali 上使用 C 中的 ncurses 编译“Hello World”

问题描述

我已经在 Kali 中成功安装了 ncurses(至少 ncurses-6.1/test 文件夹中包含的示例有效),但我自己无法编译任何东西。

我的代码:

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

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

    return 0;
}

编译失败:

gcc game.c -lncurses

fatal error: ncurses.h: No such file or directory

我已经详尽地研究了这个类似的问题,其中包括:

尽管已安装 g++ 找不到 ncurses.h

不幸的是,在尝试了包括 curses.h 与 ncurses.h 的各种排列、使用 -lncurses 或 -lncursesw 等进行编译之后,我不得不向社区寻求帮助!

标签: cgccncurses

解决方案


听起来像您手动安装的。如果是这种情况,那么您需要#include "/path/to/ncurses.h"安装它的任何地方。

如果你使用 aptitude(afaik 是默认的 Kali 包管理器),你可能需要通过apt-get install libncurses-dev.

希望有帮助。


推荐阅读