c - 为了使用 UNIX 库 punctionclear() 我需要什么头文件

标签 c unix curses

今天我在编译 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>

谢谢!

最佳答案

从显示 shr​​42_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

相应的头文件/usr/include/curses.h具有clear() ifdef的原型(prototype)

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

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

并且(假设您的编译器确实使用那个 header )后一行是使用的。从有关 gdb 的评论来看,您似乎也在使用 gcc。通常gcc会定义__STDC__(尽管某些very old端口可能不会)。如果该定义没有问题,则可能定义了_NO_PROTO。或者,您的系统可能有一些冲突的头文件。为了解决这种情况,我将生成预处理器输出文件(使用选项 -E-P-C as documented )并查看包含哪个“curses.h”文件,以及实际使用了哪个 ifdef。

关于c - 为了使用 UNIX 库 punctionclear() 我需要什么头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34219587/

相关文章:

linux - 按排序顺序获取项目中所有文件的行数。(Bash 终端)

c - 使用 NCurses 和 C 来显示系统信息的简单文本 GUI (TUI)

c - 从标准输入段错误中获取输入

C:被 dup2() 困住了 :-(

c++ - 一段时间后如何停用输入语句?

c - 为什么 Linux 不遵循 Unix 系统调用约定?

windows - 如何在DOS的ftp模式下查看unix中文件的内容?

javascript - vt100 应用程序的 Node.js/Angular 包装器

c - 链式 ncurses 程序中的终端调整大小(fork/exec/wait)

从外部程序计算使用 malloc() 分配的 block