問題
在 Visual C++ 中某些開源的源代碼時,偶爾會遇到一個問題:無法找到 dirent.h 這個文件:
Cannot open include file: ‘dirent.h’: No such file or directory
解決方案
在 Dirent API for Microsoft Visual Studio 這篇文章中提到了如何獲得 dirent.h 這個文件。可以直接從 Github: tronkko/dirent 獲得這個文件。
說明
dirent.h 是一個來自於 C POSIX library 的文件,通常被包含在 GCC (Cross-platform)、MinGW (Microsoft Windows)、Borland C++ 這些編譯器中,但是 MSVC 並不包含此文件。
幸運的是,dirent.h 有以下一些開源的實現,我們可以將其應用於 MSVC 的程序中:
- free Windows implementation of dirent.h (基於 MIT license 開源)
- POSIX Directory Browsing API for Windows (作者 Kevlin Henney 已將授權許可說明附在源代碼文件中)