First, if you want to write cross-platform code (for all of Linux, Windows, MacOSX), you might use some multi-platform framework library like POCO or Qt
Then, if you want POSIX specific function to make a directory, use mkdir function. On Linux, it is the mkdir(2) syscall (listed in syscalls(2)...). The documentation explains which headers should be included, and it is part of the C standard library on Linux.
BTW, on most Linux distributions, you often don't need to compile Boost; on Debian-like distributions (e.g. Ubuntu) you can install the libboost-all-dev
meta-package (all boost related libraries, for development) using aptitude install libboost-all-dev
or apt-get install libboost-all-dev
To get an overview of Linux programming, read Advanced Linux Programming
Also, gcc
(and other C or C++ compilers) predefines a set of preprocessor symbols. See this answer. So in your code, you might simply use #if linux
... #endif
to wrap Linux-specific code.
Notice also that POSIX is a standard specification: you should be able to compile the same code on all POSIX compliant operating systems (notably Linux, *BSD, Solaris, MacOSX). Sadly, Windows is not POSIX compliant (even if you can buy a POSIX-compliant kit from MicroSoft)
Perhaps mkdir
is available on Windows too....
Read also feature_test_macros(7)
Notice also that "create a directory in the same path as my program" is ambiguous. You can run your program in several processes, each having a different current working directory. And quite often (at least on Linux) an executable program is installed in some directory (e.g. /usr/local/bin/
, /usr/bin/
or $HOME/bin/
) mentioned in your PATH
but unwritable by most programs. Read more about the Filesystem Hierarchy Standard. So I won't persist your software data in the same directory as your program. Also, you could use application checkpointing or persist your data using sqlite or something else (PostGreSQL, MongoDB, JSON, ...)