c - ncurses库编译错误

标签 c compiler-errors ncurses

我在这个网站上查看了类似的问题,并用谷歌搜索了为什么会发生这种情况,但尝试了这些解决方案 not able to compile , difference between ncurses and curses , another compile error ,但我仍然遇到错误对 stdscr 的 undefined reference wgetch编译器正在查找库的问题,据我所知,我使用 find 找到curses 库并在#include 行中输入完整位置。

我的代码如下

#include <ncurses.h>
#include <stdio.h>
#include <string.h>

int first_line(char);
int main(){

    char c = 0;

    while((c = getch())!=EOF){
        first_line(c);

    }   

    return 0;
}

int first_line(char c){
    if (c != '\n' && c != '\r'){
            putchar(c);
        do{
            c = getch();
            putchar(c);}
            while( c !='\n');

    }
    else return 0;

    return 0;
}

如果您能指出我错过了什么或做错了什么,我将不胜感激。

最佳答案

ncurses.h 是一个头文件(包含声明),而不是一个库(包含实现这些声明的代码)。

您看到的错误消息来自链接器,而不是来自编译器。

如果您使用 gcc,则需要将 -lcurses-lncurses 添加到编译器命令行(源代码之后)文件名)。

例如,在我的系统上,我将您的源代码复制到 c.c,我可以使用其中之一来编译和链接它

gcc c.c -o c -lcurses

gcc c.c -o c -lncurses

关于c - ncurses库编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10255650/

相关文章:

c - 以下语句中的单个 & 是什么意思?

c++ - 错误 : expected unqualified-id before ‘.’ token

c - 用颜色填充 ncurses 窗口

c - 在我下面的代码中,为什么 ptr[0] 的值和地址相同。 ptr[1] 和 ptr[2] 的行为相同

c - 通过使用字符串避免 32 位溢出

c - 二进制转换器不适用于大数

c - 编译器警告消息

groovy - Groovy GString 中的变量引用

c - 在curses窗口中执行bash命令

linux - 找不到“ncurses.h”以及 'conio.h'