Include all files in a directory?

How can one achieve what the following code is trying to do?

#include "dir/*"

Solution 1:

In Bash:

HEADER=all_headers.h
echo "#ifndef __ALL_HEADERS__" > $HEADER
echo "#define __ALL_HEADERS__" >> $HEADER
for file in dir/*.h
do
    echo "#include <$file>" >> $HEADER
done
echo "#endif" >> $HEADER

Solution 2:

You can't, without running a script beforehand that generates all #include statements.

The preprocessor can only handle one file per #include statement, so it requires an actual #include for every single file you wish to be included in preprocessing.