关于APUE第一个程序编译出错问题,在线等~
从APUE的书上抄了第一个程序1-1,ourhdr.h 我是从课本后面的附录上面打上的,然后放在了/usr/include/中,程序存储为ls.c,程序如下:
#include <sys/types.h>
#include <dirent.h>
#include "ourhdr.h"
int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if(argc!=2)
err_quit("a single argument (the directory name)is required");
if((dp=opendir(argv[1]))==NULL)
err_sys("can't open %s",argv[1]);
while((dirp=readdir(dp))!=NULL)
printf("%s\n",dirp->d_name);
closedir(dp);
exit(0);
}
编译:gcc ls.c ,出错问题如下:
[root@localhost ~]# gcc ls.c
ls.c: 在函数 ‘pr_mask’ 中:
ls.c:7: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘{’ token
ls.c:21: 错误:原型函数定义中使用了旧式参数声明
ourhdr.h:35: 错误:省略了形参的名字
[root@localhost ~]#
大家帮忙看看是什么问题?谢~~
#include <sys/types.h>
#include <dirent.h>
#include "ourhdr.h"
int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if(argc!=2)
err_quit("a single argument (the directory name)is required");
if((dp=opendir(argv[1]))==NULL)
err_sys("can't open %s",argv[1]);
while((dirp=readdir(dp))!=NULL)
printf("%s\n",dirp->d_name);
closedir(dp);
exit(0);
}
编译:gcc ls.c ,出错问题如下:
[root@localhost ~]# gcc ls.c
ls.c: 在函数 ‘pr_mask’ 中:
ls.c:7: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘{’ token
ls.c:21: 错误:原型函数定义中使用了旧式参数声明
ourhdr.h:35: 错误:省略了形参的名字
[root@localhost ~]#
大家帮忙看看是什么问题?谢~~
...全文
相关推荐
Ubuntu12.04下编译成功的APUE附带源码
本资源是APUE随书附带源码库,在Ubuntu12.04下编译成功,可以直接在Ubuntu下进行Linux C学习,并且附有编译过程
linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法汇总
linux下《UNIX环境高级编程》(apue2)源码编译出错的处理方法 文章出处:http://www.diybl.com/course/3_program/c++/cppjs/2008617/126036.html 相信很多跟我一样想要学习unix编程的朋友在兴冲冲拿到《unix环境高级编程》后,准备拿源码练练手时,执行第一个myls就出现一大堆的 错误,这未免时个不小的打击。今天把解
apue.2e:ubuntu下可以编译通过的apue源代码
apue.2e:ubuntu下可以编译通过的apue源代码
Linux中搭建apue.h头文件环境
在《UNIX环境高级编程》第二版中,如果编写源代码时,需要用到apue.h这个头文件,此资料包含了apue.h头文件以及安装说明。 注:测试Linux版本:Fedora 14及Fedora 15
只使用APUE的libapue.a库文件和apue.h头文件的例程,有Makefile
将libapue.a从编译好的APUE源码库中提取出来,与自己写的c源文件放在同一目录下,并有写好的Makefile文件,在任何Linux系统下都能工作


