在 Debian(以及所有遵循 POSIX 标准的 Linux 系统)中,opendir 函数声明在头文件:
#include <dirent.h>
示例:
#include <dirent.h>
#include <stdio.h>
int main() {
DIR *dir = opendir(".");
if (dir == NULL) {
perror("opendir");
return 1;
}
closedir(dir);
return 0;
}
补充说明:
opendir 返回 DIR *readdir、closedir、rewinddir 也都在 <dirent.h>gcc test.c -o test 即可,不需要额外链接库(属于 libc)如果你说的是 “copendir”(不是 opendir),那在标准 C/POSIX 里没有这个函数,可能是拼写错误或是某个项目自定义的函数。