不能编译C / C ++ code,它是一个使用ncurses的 [英] Not able to compile C/C++ code that's using ncurses

查看:140
本文介绍了不能编译C / C ++ code,它是一个使用ncurses的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现的ncurses和刚开始学习它,但是在我的教程中的例子并不在我的电脑上进行编译。

I've just discovered ncurses and have just started learning it, however the examples in my tutorial don't compile on my computer.

我不得不手动安装的ncurses并通过输入和apt-get安装好libncurses5-dev的libncursesw5-dev的这样做了。我不得不这样做,因为之前已经做过,所以我得到一个错误说我不能的#include

I had to install ncurses manually and did so by entering "apt-get install libncurses5-dev libncursesw5-dev". I had to do this because before having done so I got an error saying that I could not "#include ".

安装它的工作,但现在我得到这个错误,而不是:

Installing it worked, but now I get this error instead:

touzen@comp:~/learning_ncurses$ g++ -o hello_world hello_world.cpp
/tmp/ccubZbvK.o: In function `main':
hello_world.cpp:(.text+0xa): undefined reference to `initscr'
hello_world.cpp:(.text+0x16): undefined reference to `printw'
hello_world.cpp:(.text+0x1b): undefined reference to `refresh'
hello_world.cpp:(.text+0x20): undefined reference to `stdscr'
hello_world.cpp:(.text+0x28): undefined reference to `wgetch'
hello_world.cpp:(.text+0x2d): undefined reference to `endwin'
collect2: ld returned 1 exit status

在code我编译如下所示:

The code I compiled looks like this:

#include <ncurses.h>
int main(){
    initscr();
    printw("Hai thar world...");
    refresh();
    getch();
    endwin();

    return 0;
}

为什么我得到这个错误。而更重要的是,我该如何解决这个问题?

Why do I get this error. And even more importantly, how do I fix this?

推荐答案

您必须ncurses库链接

you have to link the ncurses library

g++ -o hello_world hello_world.cpp -lncurses

这篇关于不能编译C / C ++ code,它是一个使用ncurses的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆