我试图用scandir
打印当前目录中的文件列表。当我尝试编译,我收到以下错误和警告:scandir的隐式声明; alphasort未声明
warning: implicit declaration of function ‘scandir’ [-Wimplicit-function-declaration]
error: ‘alphasort’ undeclared (first use in this function)
note: each undeclared identifier is reported only once for each function it appears in
我包括<dirent.h>
,其中据我所知应该定义scandir()
和所有相关的功能。而且我没有看到任何错误,在我的代码:
#include <dirent.h>
...
int printFiles(){
struct dirent **nameList;
int numOfFiles = scandir(".", &nameList, 0, alphasort);
//TODO print file names
return numOfFiles;
}
....
我运行Ubuntu 12.04,和我使用gcc
与-c99
标志进行编译。
我可以简单地忽略一些东西吗?我无法弄清楚为什么它不能编译。
不同消息的原因是编译器从上下文知道'scandir()'必须是一个函数,但从上下文无法判断'alphasort()'是一个函数。 –