在 Debian 里,opendir 并不是“引入某个库”,而是 POSIX 标准函数,来自 <dirent.h> 头文件,链接时一般也不需要额外库(在 glibc 中已包含)。
下面按常见场景说明。
opendir#include <dirent.h>
#include <stdio.h>
int main() {
DIR *dir = opendir(".");
if (dir == NULL) {
perror("opendir");
return 1;
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
return 0;
}
gcc test.c -o test
✅ 不需要 -l 任何额外库
opendirls /usr/include/dirent.h
如果没有:
sudo apt update
sudo apt install libc6-dev
opendir同样可以使用:
#include <dirent.h>
或者更推荐使用 C++17:
#include <filesystem>
编译:
g++ test.cpp -std=c++17 -o test
⚠️ Debian 官方并没有叫 copendir 的包
你可能是指:
opendir(函数)libopendir(不存在)fts, glob, nftw)如果是某个 具体库名,请告诉我:
| 函数 | 作用 |
|---|---|
opendir |
打开目录 |
readdir |
读取目录项 |
closedir |
关闭目录 |
scandir |
扫描并排序目录 |
nftw |
递归遍历目录 |
如果你愿意,可以告诉我:
我可以直接帮你定位问题。