tronkko/dirent

Running on Ubuntu

Closed this issue ยท 3 comments

Hi. I found your API very usefull and easy to use on my small project I started on Windows,
I just had to do #include "dirent.h" and everything worked perfect.

However, I wish to make my program runnable on Ubuntu, but it obviously won't compile due to windows functionality inclusions/dependency on your code... Is dirent even intended to work on Linux distributions?

Is it possible to get my program to run on Ubuntu with none to minimal functionality alterations?
This is what my program does, and how it includes your functionalities, in case it where relevant:
https://gist.github.com/Mangonels/5e35a34594ceb5c2907dcdeefa80bc0c

Thank you!

Hi,
dirent.h is part of the POSIX standard, see e.g. [1]. So it is available out of the box on Linux systems like Ubuntu.
For a cross-platform program you could use:
#ifdef _MSC_VER
#include "dirent.h"
#else
#include <dirent.h>
#endif

[1] http://man7.org/linux/man-pages/man3/readdir.3.html

You absolute machine

As an other alternative, you could put it in a directory named "windows" in your project and add as include path (only if building on Windows, obviously) so you don't even have to select between "dirent.h" and <dirent.h>.