gpt4 book ai didi

c - 为什么 linux 上的 curses 会给我以下错误?

转载 作者:太空狗 更新时间:2023-10-29 16:47:15 24 4
gpt4 key购买 nike

尝试让 getch() 工作以捕获按键。

    #include <curses.h>
...
...
WINDOW *w;
char f;

w = initscr();
timeout(3000);
f = getch();
endwin();

给我以下错误:-

undefined reference to `wgetch'
undefined reference to `stdscr'

最佳答案

这是一个链接错误。您是否正确链接到 curses 库?

在 C 中使用库涉及两个步骤。

  1. 您从源文件中#include 相关的头文件。这样您的代码就知道库函数的签名是什么。所以你做对了。
  2. 编译代码时,需要告诉链接器链接到相关的库,这样它才能找到那些函数的定义。 这是你没有做的。假设您使用的是 gcc,那么将 -lncurses 添加到编译行就可以了。这是一个 explanation of linking .

关于c - 为什么 linux 上的 curses 会给我以下错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1513417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com