如何包含文件夹中的所有源文件? (C++,MS VS 2013)

How to include all source files from folder? (C++, MS VS 2013)

我有一个简单的项目,我在其中为 C++(大数字)使用了 tiny ttmath library。 该库由 13 个 *.h 文件组成。 我以一种愚蠢的方式包含了所有这些文件:

 #include "ttmath\ttmath.h"
 #include "ttmath\ttmathbig.h"
 #include "ttmath\ttmathdec.h"
 #include "ttmath\ttmathint.h"
 #include "ttmath\ttmathmisc.h"
 #include "ttmath\ttmathobjects.h"
 #include "ttmath\ttmathparser.h"
 #include "ttmath\ttmaththreads.h"
 #include "ttmath\ttmathtypes.h"
 #include "ttmath\ttmathuint.h"
 #include "ttmath\ttmathuint_noasm.h"
 #include "ttmath\ttmathuint_x86.h"
 #include "ttmath\ttmathuint_x86_64.h"

正确的方法是什么?我期待这样的事情:

#include "ttmath\*.h"

但是找不到...

预处理器没有内置 "include all"。它也不接受文件名中的通配符。您必须手动包含所有这些。

一个常见的解决方案是将所有包含文件放在一个新的 .h 文件中,并在您每次需要所有这些文件时包含该文件。

What is the right way? I expect smth like this:

#include "ttmath\*.h"

but can not find...

这是行不通的,因为预处理器不会扩展字符来匹配您希望通配符工作的方式。

我的建议是创建一个您自己的自定义 header 文件,并将所有 #include 条目放入其中。例如,在您的 .c 文件中,您可以添加自己的 header:

#include "my_header.h"

my_header.h 的内容为:

#include "ttmath\ttmath.h"
#include "ttmath\ttmathbig.h"
#include "ttmath\ttmathdec.h"
#include "ttmath\ttmathint.h"
#include "ttmath\ttmathmisc.h"
#include "ttmath\ttmathobjects.h"
#include "ttmath\ttmathparser.h"
#include "ttmath\ttmaththreads.h"
#include "ttmath\ttmathtypes.h"
#include "ttmath\ttmathuint.h"
#include "ttmath\ttmathuint_noasm.h"
#include "ttmath\ttmathuint_x86.h"
#include "ttmath\ttmathuint_x86_64.h"

基本上,您将所有内容都放在一个 header 中,然后包含那个。