大规模c/c++工程的的代码组织,也就是和逻辑结构相区别的物理结构也非常重要。不合理的文件结构组织会导致以下问题:
1 编译时间加长
2 名字空间污染
3 不便于单独重用
4 如果用到开源软件或第三方软件,可能的版权问题
为了比较好的组织物理结构,大致代码组织如下:
Project
|-public //code under GPL license with link exception
|
|-private//proprietary code
|--app1
|---export
|---include
|---source
|--app2
|---export//header files for external modules use
|---include//header files for internal module use
|---souce//implementation code
|--lib
|
|-gpl//GPL applcation
这样组织的目的主要是:
一. 把给外部模块和给模块内代码使用的头文件区分开,就可以在工程的Makefile里把所有export目录下的路径包含进来,从而在各模块引用其他模块代码是使用相对模块名的路径格式,增加了一个间接层,保证了模块路径的可修改性。
二. 对于使用GPL软件的项目,解决了许可证的问题:
The GPL requires that any derivative code of the GPL code be subject to the GPL license.This means that if a proprietary library links with a GPL application in a way that is viewed as "derivative work" or "based on" GPL application , then the source code of the proprietary library must be distributed under the same terms as the original GPL license.
GPL许可证要求任何从CPL代码衍生的代码遵从CPL许可证。这意味着私有的库如果按照可以被视作从GPL应用衍生或基于GPL应用的方式链接的话,就必须要遵从CPL许可证。如果
这意味着需要保护的代码不能直接和GPL的代码链接。那么怎么解决呢?就是增加一个中间层,在这一层里的代码是和GPL链接,也是under GPL license, but with link exception.这样其他和这个中间层链接的代码就不用under GPL license.
而这个public的目录就是这种中间层。通过public目录下提供对GPL 代码的包装,又使用排除链接的许可证就能保证private目录下的代码可以和public里的库链接,从而间接使用CPL的服务。
本文探讨了大规模C/C++项目的代码组织策略,包括如何合理地划分公共与私有代码,以及如何处理GPL许可下的代码集成问题。文章还介绍了通过中间层隔离GPL代码的方法。
1143

被折叠的 条评论
为什么被折叠?



