对于使用 Makefile 的大型 C 项目,什么是好的目录结构?

新手上路,请多包涵

对于使用 Makefile 的大型 C++ 项目,什么是好的目录结构?

这是我的目录结构目前的样子:

 lib/ (class implementations *.cpp)
include/ (class definitions *.h)
tests/ (main.cpp for quick tests)

现在,我不确定我的 Makefile 应该是什么样子……当 .cpp 文件和 .h 文件不在同一个目录中时,它似乎不起作用。谁能给我指出一个带有 Makefile 的通用目录结构,这样我就不会重新发明轮子?

原文由 Olivier Lalonde 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 855
1 个回答

对于那些在 2020 年之后发现这个问题的人,Boris Kolpackov 提出了另一种现代且合理的 C++“规范项目结构”愿景: http ://www.open-std.org/jtc1/sc22/wg21/docs/ 论文/2018/p1204r0.html

简而言之 - 没有 include/src/ 拆分。所有头文件、源代码、模块和单元测试都放在一个目录中。通过移动到 <name>/<name>/details/ 子目录,可以将实现细节与公共 API 分开。

 <name>/
├── <name>/
│   ├── headers...
│   ├── sources...
│   ├── modules...
│   └── unit tests...
└── tests/
    ├── functional_test1/
    ├── functional_test2/
    ├── integration_test1/
    ├── integration_test2/
    └── ...

例如:

 bestlib/
├── bestlib/
│   ├── foo.h
│   ├── foo.cpp
│   ├── foo.test.cpp
│   ├── bar.h
│   ├── bar.cpp
│   └── bar.test.cpp
└── tests/
    ├── functional_test1/
    └── integration_test1/

原文由 4LegsDrivenCat 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题