请教:终端编程连接出错的问题

软件和网站开发以及相关技术探讨
回复
bluefans
帖子: 14
注册时间: 2007-06-03 15:29

请教:终端编程连接出错的问题

#1

帖子 bluefans » 2008-06-26 18:09

自己写了一个小程序,练习终端编程:
#include<stdio.h>
#include<term.h>
#include<curses.h>

int main()
{
int nrows, ncols;
setupterm((char *)0, 1, (int *)0);
nrows = tigetnum("lines");
ncols = tigetnum("cols");
printf("This terminal has %d cols and %d rows\n", ncols, nrows);
exit(0);
}
编译时出现如下错误:
sizeterm.c:(.text+0x29): undefined reference to `setupterm'
sizeterm.c:(.text+0x35): undefined reference to `tigetnum'
sizeterm.c:(.text+0x44): undefined reference to `tigetnum'
我查看库里已经安装了libncurses,为什么连接时会出错?
ls -l libncurses*
-rw-r--r-- 1 root root 428524 2007-10-08 18:07 libncurses.a
-rw-r--r-- 1 root root 144292 2007-10-08 18:07 libncurses++.a
lrwxrwxrwx 1 root root 20 2008-06-26 17:51 libncurses.so -> /lib/libncurses.so.5
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#2

帖子 BigSnake.NET » 2008-06-26 18:16

gcc -lcurses foo.c
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
bluefans
帖子: 14
注册时间: 2007-06-03 15:29

#3

帖子 bluefans » 2008-06-27 9:46

多谢,确实可以连接通过,标准的库为何还需要指定?
头像
liuqun67
帖子: 101
注册时间: 2008-05-29 22:53
来自: 青岛/南京
联系:

#4

帖子 liuqun67 » 2008-07-03 14:48

只有标准C库libc不用指定
其他像libcurses, libm都要用-l选项指定
回复