SQLite and googletest come with a very easy-to-use, single-file version which makes it a breeze to use it in other projects, as you just need to add a single source file. Both of them use home-brew tools to create the combined source file, so I wonder if there is a more generic tool for this? It should take a list of implementation/header files and spit out a combined header/source, and fix up the local includes. I'm fine if it doesn't handle conditional includes/includes with different #defines
before them like Boost.Tuple/MPL uses them. A typical target library would be something like ICU.
SQLite和googletest提供了一个非常容易使用的单文件版本,这使得在其他项目中使用它变得非常容易,因为您只需要添加一个源文件。他们都使用自制的工具来创建合并的源文件,所以我想知道是否有更通用的工具来实现这一点?它应该包含一个实现/头文件的列表,并输出一个合并的头/源文件,并修复本地的包含。如果它不处理带有不同#定义的条件包含/包含(比如Boost),那就没问题。元组/ MPL使用它们。典型的目标库应该是ICU。
3 个解决方案
#1
3
If your includes are correctly defined (that is, there are guards in all header files, and each header/code unit contains all includes that it requires) then you can do it 'half-manually'. Locate system header includes and comment them out, then create a header that just includes everything in any random order and preprocess the header (in gcc that would be gcc -E
) and then operate similarly with the code units.
如果include被正确定义(也就是说,在所有头文件中都有保护,并且每个头/代码单元都包含它所需要的所有包含),那么您可以“半手动”地完成它。找到system header包含并注释掉它们,然后创建一个header,其中包含任意顺序的所有内容,并对header进行预处理(在gcc中,就是gcc -E),然后与代码单元进行类似的操作。
This manual approach can be cumbersome, but if you only need to do it once it will be fine. Then again, even if merging the header files might make sense I prefer not to do it. I would actually leave the files separate, and if you feel like you need to simplify access to it, provide bundling headers that just include the others. This is the approach that some boost libraries take, where you can include the details of what you want or a single header that includes everything else. The code can be compiled/linked into an static lib and used as if it was a single element.
这种手工方法可能很麻烦,但是如果您只需要做一次就可以了。然后,即使合并头文件可能有意义,我也不愿意这样做。实际上,我将把这些文件分开存放,如果您觉得需要简化对它们的访问,可以提供包含其他文件的打包头。这是一些boost库所采用的方法,您可以在其中包括您想要的细节或包含其他所有内容的单个标题。可以将代码编译/链接到静态库中,并将其用作单个元素。
#2
3
try this https://github.com/vinniefalco/Amalgamate/ may be it can help...
试试这个https://github.com/vinniefalco/Amalgamate/可能会有帮助…
#3
1
This might be sort of interesting in ICU, which has, in some cases, incompatible defines/includes and mixtures of C and C++ and a number of generated files. Maybe let us know how it goes?
这在ICU中可能有点意思,在某些情况下,ICU定义/包含和混合了C和c++以及许多生成的文件。也许让我们知道怎么回事?
(disclosure: icu developer)
(披露:icu开发人员)
#1
3
If your includes are correctly defined (that is, there are guards in all header files, and each header/code unit contains all includes that it requires) then you can do it 'half-manually'. Locate system header includes and comment them out, then create a header that just includes everything in any random order and preprocess the header (in gcc that would be gcc -E
) and then operate similarly with the code units.
如果include被正确定义(也就是说,在所有头文件中都有保护,并且每个头/代码单元都包含它所需要的所有包含),那么您可以“半手动”地完成它。找到system header包含并注释掉它们,然后创建一个header,其中包含任意顺序的所有内容,并对header进行预处理(在gcc中,就是gcc -E),然后与代码单元进行类似的操作。
This manual approach can be cumbersome, but if you only need to do it once it will be fine. Then again, even if merging the header files might make sense I prefer not to do it. I would actually leave the files separate, and if you feel like you need to simplify access to it, provide bundling headers that just include the others. This is the approach that some boost libraries take, where you can include the details of what you want or a single header that includes everything else. The code can be compiled/linked into an static lib and used as if it was a single element.
这种手工方法可能很麻烦,但是如果您只需要做一次就可以了。然后,即使合并头文件可能有意义,我也不愿意这样做。实际上,我将把这些文件分开存放,如果您觉得需要简化对它们的访问,可以提供包含其他文件的打包头。这是一些boost库所采用的方法,您可以在其中包括您想要的细节或包含其他所有内容的单个标题。可以将代码编译/链接到静态库中,并将其用作单个元素。
#2
3
try this https://github.com/vinniefalco/Amalgamate/ may be it can help...
试试这个https://github.com/vinniefalco/Amalgamate/可能会有帮助…
#3
1
This might be sort of interesting in ICU, which has, in some cases, incompatible defines/includes and mixtures of C and C++ and a number of generated files. Maybe let us know how it goes?
这在ICU中可能有点意思,在某些情况下,ICU定义/包含和混合了C和c++以及许多生成的文件。也许让我们知道怎么回事?
(disclosure: icu developer)
(披露:icu开发人员)