- 论坛徽章:
- 0
|
试着写了个名为gethost.c的小程序,程序如下:
#include<stdio.h>;
#include<stdlib.h>;
#include<unistd.h>;
#include<errno.h>;
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
main()
{
char hostname[MAXHOSTNAMELEN];
long hostid;
size_t size;
size=MAXHOSTNAMELEN;
if(gethostname(hostname,size)!=0)
{
printf("Could not get host name\n" ;
exit(1);
}
hostid=gethostid();
printf("hostname=%s\nhostid=%d\n",hostname,hostid);
}
然后用GCC编译
#gcc gethost.c
却出现如下提示:
Undefind first referenced
symbol in file
gethostname /usr/tmp/ccr2Qcnv.o
a.out:fatal error:Symbol veferencing errors.
No output written to a.out
collect 2:ld returned 1 exit status
出现个致命错误的提示,不能编译,不知什么原因??
谢谢! |
|