代码: 全选
/*
照《Unix/Linux编程 实践教程》这本书上抄的源代码,但系统不一样
英文名:《Understanding Unix/Linux Programming》
这个程序功能:编写类似系统的who命令
*/
#include<stdio.h>
#include<utmp.h>
#include<fcntl.h>
#include<unistd.h>
#define SHOWHOST
int main(){
struct utmp current_record;
int utmpfd;
int reclen = sizeof(current_record);
if((utmpfd = open(UTMP_FILE, O_RDONLY)) == -1){
perror(UTMP_FILE);
exit(1);
}
while(read(utmpfd, ¤t_record, reclen) == reclen)
show_info(¤t_record);
close(utmpfd);
return 0;
}
show_info(struct utmp *utbufp)
{
printf("%-8.8s", utbufp->ut_name);
printf(" ");
printf("%-8.8s", utbufp->ut_line);
printf(" ");
printf("%10ld", utbufp->ut_time);
printf(" ");
#ifdef SHOWHOST
printf("(%s)", utbufp->ut_host);
#endif
printf("\n");
}
保存为who1.c
以下是编译
chen@chen-notebook:~$ gcc who1.c -l who1
who1.c: 在函数‘main’中:
who1.c:15: 警告: 隐式声明与内建函数‘exit’不兼容
/usr/bin/ld: cannot find -lwho1
collect2: ld 返回 1
chen@chen-notebook:~$
------------------
问这是什么原因?
我GOOGLE半天,看到很多人都有相同问题,只-lwho1这点不一样,各种各样的解决办法,我试了很多都不行