:link_to_translation:en:[English]
使用旧工具链的代码可能会出现编译错误。例如:
#include <sys/dirent.h>
/* .... */
DIR* dir = opendir("test_dir");
/* .... */
/**
* Compile error:
* test.c: In function 'test_opendir':
* test.c:100:16: error: implicit declaration of function 'opendir' [-Werror=implicit-function-declaration]
* 100 | DIR* dir = opendir(path);
* | ^~~~~~~
*/
包含正确的头文件即可解决此问题。请将代码重构如下:
#include <dirent.h>
/* .... */
DIR* dir = opendir("test_dir");