header 我需要什么才能使用 UNIX 库标点符号 clear()

What header do I need in order to use UNIX library punction clear()

今天我正在编译我的 UNIX 的源代码时,我注意到以下内容

warning: implicit declaration of function 'clear'

在我用 GDB 对二进制文件进行调试后,结果如下:

0x090000002a242594 in clear () from /usr/lib/libcurses.a(shr42_64.o)
0x090000002a242600 in wclear () from /usr/lib/libcurses.a(shr42_64.o)
0x090000002a238a80 in werase () from /usr/lib/libcurses.a(shr42_64.o)
0x090000002a238b00 in wmove () from /usr/lib/libcurses.a(shr42_64.o)
0x090000002a238a9c in werase () from /usr/lib/libcurses.a(shr42_64.o)
0x090000002a238600 in wclrtobot () from /usr/lib/libcurses.a(shr42_64.o)
0x090000002a237f80 in wclrtoeol () from /usr/lib/libcurses.a(shr42_64.o)

它似乎是某种 UNIX 库 "libcurses.a"

我应该如何将此库包含在我的文件中才能消除该警告?

#include <stdlib.h>
#include <curses.h> // See it's here, stop the silly questions
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

谢谢!

此错误与包含库和包含函数声明无关,这意味着您需要 #include <curses.h>。 (参见 man 页)

从堆栈跟踪显示 shr42_64.o,您的系统似乎是某个版本的 AIX,例如 5.x。 运行

ar tv /usr/lib/libcurses.a

会显示类似

的内容
r--r--r--     2/2     493219 Aug 05 05:38 2011 shr42.o
r--r--r--     2/2     377211 Aug 05 05:38 2011 shr4.o
r--r--r--     2/2     194484 Aug 05 05:38 2011 shr.o

对应的header/usr/include/curses.hclear()的原型ifdef'd within

#if     defined(NOMACROS) || defined(lint)

#if defined(__STDC__) || !defined(_NO_PROTO)

and(假设你的编译器真的使用 that header)后一行是 used。从关于 gdb 的评论来看,您似乎也在使用 gcc。通常 gcc 会定义 __STDC__(尽管有些 very old port may not). If there is no problem with that definition, it is possible that something defined _NO_PROTO. Alternatively, your system could have some conflicting header file. To resolve what is the case, I would generate the preprocessor-output file (using options -E, -P and -C as documented)并查看包含了哪个 "curses.h" 文件,以及实际使用了哪个 ifdef。