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