在Linux上使用的ncurses时未定义参考 [英] Undefined reference when using ncurses on linux

查看:280
本文介绍了在Linux上使用的ncurses时未定义参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始开发在Linux上使用ncurses的程序。我甚至不能得到Hello World示例进行编译。这里的code:

I'm trying to start developing a program using ncurses on Linux. I can't even get the Hello World example to compile. Here's the code:

#include <curses.h>
int
main()
{         
        initscr();
        printw("Hello, world.");
        refresh();
        getch();
        endwin();
        return 0;
}

当我尝试编译,我得到:

When I attempt to compile, I get:

hello.c:(.text+0x12): undefined reference to `iniscr'

有关每一个人的那些caled功能。

For every one of the those caled functions.

我安装通过apt-get的ncurses的,也可以通过下载的来源和编译,安装等。

I installed ncurses via apt-get, and also by downloading the sources and compiling, installing, etc.

我已经试过的#include都curses.h里和ncurses.h。

I have tried #include both curses.h and ncurses.h.

这是怎么回事?

推荐答案

你有没有连接时使用的 -lcurses 选项?

Have you used the -lcurses option when linking?

包括头文件让code编译(因为编译器知道函数调用的样子从 .H 文件),但链接器需要库文件找到实际的code链接到程序中。

Including the header files let the code compile (because the compiler knows what the function call looks like from the .h file), but the linker needs the library file to find the actual code to link into your program.

这篇关于在Linux上使用的ncurses时未定义参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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