静态链接的ncurses编程 [英] Statically link ncurses to program

查看:205
本文介绍了静态链接的ncurses编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题静态链接的ncurses到我的节目之一

I'm having some problems statically linking ncurses to one of my programs

下面是一个非常简单的示例程序:

Here's a really simple sample program:

#include<ncurses.h>


int main(){

    initscr();
    printw("Hello world\n");
    refresh();
    getch();
    endwin();
    return 0;
}

当我编译

gcc -static -lncurses hello_curses.c -o curses

我得到这些错误:

I get these errors:

/tmp/ccwHJ6o1.o: In function `main':
curses_hello.c:(.text+0x5): undefined reference to `initscr'
curses_hello.c:(.text+0x14): undefined reference to `printw'
curses_hello.c:(.text+0x1b): undefined reference to `stdscr'
curses_hello.c:(.text+0x20): undefined reference to `wrefresh'
curses_hello.c:(.text+0x27): undefined reference to `stdscr'
curses_hello.c:(.text+0x2c): undefined reference to `wgetch'
curses_hello.c:(.text+0x31): undefined reference to `endwin'
collect2: ld returned 1 exit status

我有点困惑,为什么这是行不通的。缺少什么我在这里?

I'm a little confused why this isn't working. What am I missing here?

推荐答案

您需要通过 -l <​​/ code>选项在命令行的末尾:

You need to pass -l options at the end of the command line:

gcc -static hello_curses.c -o curses -lncurses

当编译器遇到 -lfoo ,它在所有的符号链接从已要求由previous文件。如果你把 -lfoo 开头,没有符号被要求呢,所以没有符号是联系在一起的。

When the compiler encounters -lfoo, it links in all the symbols from foo that have been requested by a previous file. If you put -lfoo at the beginning, no symbol has been requested yet, so no symbol gets linked.

这篇关于静态链接的ncurses编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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