- 论坛徽章:
- 0
|
sun的man手册好粗心呀
gcc怎么编译不通过,有大侠指点一下吗?
#include <stdio.h>;
#include <stdlib.h>;
#include <unistd.h>;
#include <errno.h>;
#include <sys/types.h>;
#include <dirent.h>;
#include <string.h>;
/*extern int scandir(const char *dirname, struct dirent ***namelist, \
int (*select)(struct dirent *), int (*compar)(const void *, const void *));
*/
extern int scandir(const char *dirname, struct dirent *(*namelist[]),int (*select)(struct dirent *), int (*compar)(struct dirent **, struct dirent **));
extern int alphasort(const void *d1, const void *d2);
/*
* Select only those direntory entries that start with
* 'h'to demonstrate the selection ability :
*/
static int my_select(struct dirent *dp)
{
if ( dp->;d_name[0] != 'h')
return 0; /* Don't include this */
return 1; /* else include this one*/
}
/*
* Sort entries in reverse order for demonstration
* purposes :
*/
static int my_compar(struct dirent **d1,struct dirent **d2)
{
struct dirent *dir1 = *d1;
struct dirent *dir2 = *d2;
/*
* Reverse the comparison by reversing
* dir2 with dir1 in the strcmp(3) call:
*/
return strcmp(dir2->;d_name,dir1->;d_name);
}
/*
* A good test is the direntory /etc :
*/
int main(int argc,char **argv)
{
int x; /* Work index */
int n; /* namelist[n] */
struct dirent **namelist; /* List of names */
if ( argc < 2 )
{
fputs("A pathname argument is required.\n, Try /etc for the direntory.\n",stderr);
return 1;
}
/*
* Scan the direntory given :
*/
n = scandir(argv[1],&namelist,my_select,my_compar);
/*
* Report the direntory entries :
*/
printf("%d entries for %s:\n",n,argv[1]);
for ( x=0; x<n; ++x )
printf("%3d: %s\n",x,namelist[x]->;d_name);
if ( n >; 0 )
{
for ( x=0; x<n; ++x )
free(namelist[x]); /* Release entry */
free(namelist); /* Release the array */
}
return 0;
}
编译
$g++ scandir.c
后返回下面的错误
未定义 文件中的
符号 在文件中
scandir(char const*, dirent***, int (*)(dirent*), int (*)(dirent**, dirent**))/var/tmp//ccdpIoK3.o
ld: 致命的: 符号参照错误. 没有输出被写入a.out
collect2: ld returned 1 exit status
是什么错误呀?请指教。 |
|