c++ - 构建 obj 和 exe 文件的最佳目录结构是什么?

标签 c++ version-control mercurial build makefile

我制作 makefile 已经有一段时间了。它支持通过使用 include 轻松创建 exe、lib 和 dll 类型的项目。

现在我又开始使用 mercurial,我注意到一切都很好很干净直到我做了一个构建。你看,我将我的目标文件放入每个子项目的源目录下的子目录中。我将我的 lib、exe 和 dll 文件构建到主工作目录下的目录中。这意味着每当我执行 hg status 时,它都会列出这些带有“?”的临时二进制文件,这是我不想要的视觉困惑。 (这不是 mercurial 的错,当然我不会天真地将它们 checkin repo 协议(protocol)或类似的东西。)我只希望 hg status 发现我可能忘记正确添加的文件,而不是这些临时构建的文件.

当前的目录结构是这样的:

projroot
-- subproj1 (for source files)
-- subproj1/intr  (for object files, release build)
-- subproj2 (for source files)
-- subproj2/intr  (for object files, release build)
-- bin (for exes and dlls)
-- lib (for libraries that I build)

所以我正在考虑重组 makefile 以将构建的文件(objs libs dll 和 exe)保留在工作目录之外。大多数人是否将所有二进制文件保存在 projroot 之上一级的目录中以避免 SCM 看到它们?必须有一些最佳实践。我使用的似乎不错,但我认为它有点过时了,当然是因为我看到了 ant 为 Java src 和类创建完全独立的树的方式。

这个结构呢?

projroot (contains common makefile includes and repo in here)
-- subproj1 (for source files)
-- subproj2 (for source files)
build
-- subproj1/intr (.o / .obj files in release build)
-- subproj1/intd
-- subproj2/intr
-- subproj2/intd
-- lib (all built libs)
-- bin (all built exes and DLLs)

构建目录在工作目录之外,因此我们使用的任何 SCM 都会忽略它。

您的回答必须考虑到 projroot 中的通用 makefile 源代码以及存在多个项目的事实,每个项目都有自己的内置二进制文件集合,您可能希望单独分发这些二进制文件。

最佳答案

我个人更喜欢这样的目录结构,因为我不喜欢任何源代码子文件夹被编译的中间文件污染。清理只是删除输出文件夹的问题

projroot
-- subproj1 (for source files)
-- subproj2 (for source files)
-- output/bin (for exes and dlls)
-- output/lib (for libraries that I build)
-- output/subproj1/ ( for *.o files )
-- output/subproj2/ ( for *.o files )

这有一个额外的好处,我可以将整个输出文件夹设置为由源代码控制管理忽略,并且我不必检查 SCM 软件来查看生成了哪些文件以及哪些版本受控。

关于c++ - 构建 obj 和 exe 文件的最佳目录结构是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8943326/

相关文章:

git - Subversion 而不是 Git 允许空文件夹是否正确?

database - 在 Git 中处理数据库的正确方法是什么?

git - 我可以像 git 一样跳过 Mercurial 预提交钩子(Hook)吗?

mercurial - tortoiseHG 突然失败并显示 "Unable to remove file xxx permission denied"

mercurial - 如何使用 mercurial 检查您所在的分支

c++ - 使用 QFileSystemModel 和 QSortFilterProxyModel 子类过滤特定文件夹的文件

c++ - 计算器返回0值,不能输入双数

c++ - 为什么这段使用 printf 和 cout 的代码没有预期的输出?

c++ - 有没有办法在编译时检测是否可以使用给定的一组参数类型成功调用通用 lambda?

git - 如何将使用 'git replace'编辑的历史推送到远程