构建 C++ 的正确方法是什么?项目?制作/IDE/Ant...?

发布于 2025-01-01 10:19:19 字数 351 浏览 2 评论 0原文

有多种方法可以管理项目的构建。我知道这些可能性:

  • IDE
  • Ant
  • Maven

我们可以说其中一些(甚至是我不知道的其他一些?)总体上优于其他,并且在新项目中绝对应该首选?

目前,我在项目中使用由 Eclipse IDE 管理的构建,并考虑迁移到 makefile。不知何故,我觉得它会更易于管理,但另一方面,让事情变得更易于管理实际上是 IDE 的目标。那么,我是否会做有害的工作,试图回到老式的东西呢?我从 Java 项目中获得了使用 Maven 的丰富经验,但是用 C++ 强制使用 Maven 是一个好主意吗(尽管我知道这是可能的......)?

There is number of ways how to manage a build of a project. I know about these possibilities:

  • Make
  • IDE
  • Ant
  • Maven

Can we say that some of them (or even some other that I don't know?) is in general superior to the others and should be definitely preferred on a new project?

At this moment I use on my project a build managed by Eclipse IDE and I consider migrating to makefiles. Somehow I feel that it will be more manageable, but on the other hand, it is actually the goal of IDEs to make things more manageable. So am I just going to do harmful work trying to return to something old fashioned? I have a great experience with Maven from a Java project, but is it a good idea to force it with C++ (although I know that it is possible...)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘落散花 2025-01-08 10:19:19

大多数仍然存在的 C++ 构建系统这样做是有原因的。也就是说,它们在某些方面比替代方案更好。 (除了让您编写 XML 的构建系统,抱歉 ANT)

但总的来说,我们看到出现了一些使用模式。

通常,您只能看到用于 MSVC 和 XCode 的 IDE 项目。这是由于与 IDE 更好的集成,是的。但更重要的是平台。 IDE 项目对 VC++ 的支持特别好,但除最终生成项目的内容外,其他方面的支持通常很差。我从未见过使用 Eclipse 构建的 C++ 项目,但这可能与从未见过在 Eclipse 中编写代码的 C++ 程序员有关。

在 UNIX 平台上,您通常会看到使用 Makefile 的某些变体。这似乎与想要一个好的最不常见的恶魔来构建项目有关,因为大多数代码都是以源代码形式分发的。

当平台独立性是首要任务时,通常会使用像 CMake(项目生成器)这样的项目,由于生成 -> 构建步骤的进行,您会获得一些开销,但能够从单个构建库在多个平台上构建项目。

我确实只看到 ANT 用于执行连续构建,即使如此,通常它也会调用单独的构建步骤,我不确定这是为什么。

然后,我还看到在针对 *nix/Mac 或其他不太常见平台的专有项目中,诸如 Jam(制作替换)之类的东西被大量使用。特别是在游戏开发中,我认为这通常来自理论上喜欢 Make 的团队(像对待代码一样对待构建源的概念,而不是所见即所得等),但了解 Make 已经被破坏了。但还可以享受不必进行源代码分发的奢侈。

这只是我观察到的一堆模式,并试图将其合理化,其中很少是基于客观事实的。

Most C++ build systems that still exist, do such for a reason. Which is to say, they are better than the alternatives in some way. (Except the build systems that have you writing XML, sorry ANT)

But in general, we see some patterns of usage emerge.

You in general only see IDE projects used for MSVC and XCode. This is due to the better integration, with the IDE, yes. But more importantaly, the Platform. VC++ is particularly well supported by the IDE projects, and generally has very poor support otherwise, except for things which end up generating the projects. I've never seen a c++ project that builds with eclipse, but that may be related to not ever seeing c++ programmers who code in Eclipse.

On unix platforms, you generally see some variant of Makefiles being used. It seems that this is related to wanting a good least common demonitor to build projects from, since most code is distributed in source form.

Projects like CMake (project generators) are often used when platform independience is a top priority, you gain some overhead due to generate->build steps going on, But gain being able to build the project on multiple platforms from a single buildbase.

I've really only seen ANT used to performing continious builds, and even then, generally it calls a seperate build step, I'm not sure why this is.

Then I've also seen a lot of usage for things like Jam(make replacements) in proprietary projects that target *nix/Mac or other less common platforms. Particularly in game development, I think this is generally from teams that like Make in theory (The concept of treating your buildsource like you treat your code, no WYSIWYG and the like) but understand that Make is broken. Yet have the luxury of not having to do source distributions.

This is just a bunch of patterns I've observed, and trying to rationalize it, very little of this is based on objective-truths.

小清晰的声音 2025-01-08 10:19:19

在追求平台独立性时,我使用 Cmake 取得了很好的结果。它的配置基于文本文件,并生成“真正的”构建脚本,例如 Makefile 或适用于 IDE 的项目。如果您对引入某种预构建步骤没有问题,我会这样做。

如果我可以保持平台依赖性,我就选择我喜欢的任何东西。通常是 Windows 上的 Visual Studio 项目/解决方案和 Linux 上的 Makefile。

When going for platform independency, I have achieved good results using Cmake. Its configuration is based on textfiles and it produces "real" build scripts like Makefiles or the appropriate projects for IDEs. If you have no problem with introducing some sort of pre-build step, I would go for it.

In cases where I can stay platform dependent, I just go with whatever I prefer. Typically Visual Studio Projects / Solutions on Windows and Makefiles on Linux.

镜花水月 2025-01-08 10:19:19

我假设您正在使用 Eclipse CDT。构建过程实际上已经基于 Makefile。但是,我认为 CDT 在编译时生成 Makefile。也许其他人可以帮我验证这一点。无论如何,在 CDT 中您可以创建一个“Makefile”项目。这种类型的项目允许您使用预先存在的源代码及其 Makefile,而不是从头开始。

另一件需要考虑的事情是您是否需要支持无头构建(例如作为 CI 或其他自动化构建过程的一部分)?如果是这样,那么您一定要选择支持该功能的构建技术(例如 Make)。

有关 CDT 如何使用 Makefile 的信息: Eclipse 文档

I'm assuming you are using the Eclipse CDT. The build process is actually Makefile-based already. However, I think the CDT generates the Makefile at compile time. Perhaps somebody else could verify that for me. Regardless, in the CDT you can create a "Makefile" project. That type of project allows you to use pre-existing source and its Makefile instead of starting from scratch.

Another thing to consider is do you have a requirement to support headless builds (e.g. as part of a CI or other automated build process)? If so, then you will want to definitely choose a build technology that supports that (like Make).

For info on how CDT uses Makefiles: Eclipse documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文