组合C ++头文件 [英] Combining C++ header files

查看:85
本文介绍了组合C ++头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种自动方式来处理大量C ++头文件并将它们组合为一个文件?

Is there an automated way to take a large amount of C++ header files and combine them in a single one?

当然,此操作必须以正确的顺序连接文件,以便在将要用于以后的类和函数中之前,不定义类型等.

This operation must, of course, concatenate the files in the right order so that no types, etc. are defined before they are used in upcoming classes and functions.

基本上,我正在寻找可以将我的库分发到两个文件(libfoo.h, libfoo.a)中的东西,而不是当前的包含文件+二进制库的文件.

Basically, I'm looking for something that allows me to distribute my library in two files (libfoo.h, libfoo.a), instead of the current bunch of include files + the binary library.

推荐答案

正如您的评论所述:

..我想使库用户更容易使用,因此他们只需执行一个#include就可以了.

.. I want to make it easier for library users, so they can just do one single #include and have it all.

然后,您可以花一些时间,以正确的顺序将所有标头包括在包装器"标头中. 50个标题不是很多.只需执行以下操作即可:

Then you could just spend some time, including all your headers in a "wrapper" header, in the right order. 50 headers are not that much. Just do something like:

// libfoo.h
#include "header1.h"
#include "header2.h"
// ..
#include "headerN.h"

如果您手动执行此操作,则不会花费太多时间.

This will not take that much time, if you do this manually.

此外,稍后再添加新标头(只需几秒钟),即可将其添加到此包装标头"中.

Also, adding new headers later - a matter of seconds, to add them in this "wrapper header".

我认为,这是最简单,最干净,最有效的解决方案.

In my opinion, this is the most simple, clean and working solution.

这篇关于组合C ++头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆