开发者

Include all files in a directory?

开发者 https://www.devze.com 2023-01-04 07:03 出处:网络
How c开发者_高级运维an one achieve what the following code is trying to do? #include \"dir/*\" In Bash:

How c开发者_高级运维an one achieve what the following code is trying to do?

#include "dir/*"


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


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.


One way to achieve that is to write a convenience header that includes all the headers you want. Keep in mind that including headers you will not use may unnecessarily increase compilation time.


Look at how Boost does this for, say, utility.hpp.

$ cat /usr/include/boost/utility.hpp
//  Boost utility.hpp header file  -------------------------------------------//
<snip>
#ifndef BOOST_UTILITY_HPP
#define BOOST_UTILITY_HPP

#include <boost/utility/addressof.hpp>
#include <boost/utility/base_from_member.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/checked_delete.hpp>
#include <boost/next_prior.hpp>
#include <boost/noncopyable.hpp>

#endif  // BOOST_UTILITY_HPP

Now you can just use #include <boost/utility.hpp>.

0

精彩评论

暂无评论...
验证码 换一张
取 消