将 Maven 用于 C/C++项目

发布于 2024-08-07 00:10:13 字数 472 浏览 3 评论 0原文

我将 Maven 构建围绕业余爱好者、编写糟糕且坦率地说的原始 C/C++ 代码(意味着一些 C,一些 C++)的集群。问题是——目前有很多在流通,并且不能轻易更换。构建它需要大量的部落知识(你必须从一个立方体到另一个立方体才能找出如何编译/构建各个部分),而发布完全是噩梦。我不会重写它,请不要建议。

我应该使用 maven-native-plugin 来替换大量短 makefile 还是使用 exec-maven-plugin 来简单地执行这些文件? 我有非常好的体验到目前为止,后者正在使用 .NET,不知道我是否应该投资 native 插件还是继续使用 exec?如果您有“Mavenizing”C/C++ 的经验,我很想得到一些建议。

I'm putting Maven build around cluster of amateur, poorly written and frankly - primitive C/C++ code (meaning some C, some C++). Problem is - there's lots of it in circulation currently and cannot be easily replaced. Building it requires a lot of tribal knowledge (you have to go from cube to cube just to find out how to compile/build various parts) and releasing is total nightmare. I'm not going to rewrite it, please don't suggest that.

Should I use maven-native-plugin to replace the multitude of short makefiles or use exec-maven-plugin to simply execute these?
I had pretty good experience so far with the latter doing .NET and don't know if I should invest into native plugin or stay with exec? If you had experience with "Mavenizing" C/C++ I would love to get some advice.

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

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

发布评论

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

评论(2

你的笑 2024-08-14 00:10:13

我强烈推荐 maven-nar-plugin。我发现它在很多方面都优于其他选择。它不需要列出源文件,处理多个操作系统和架构,处理单元和集成测试,并且通常遵循“maven 方式”。它引入了一种新的打包方式 - NAR 或“本机存档”,其中包含您关心的工件(.dll、.so、.a、.exe 等),而且还包含元数据、标头等。有意义的方式。

将第三方软件打包到 NAR 中确实需要一些前期工作,但它非常简单。一旦它们成为 NAR,您只需使用普通的 Maven 依赖机制来与它们链接,例如:

<dependency>
  <groupId>cppunit</groupId>
  <artifactId>cppunit</artifactId>
  <scope>test</scope>
</dependency>

一个缺点是它似乎没有被积极维护,但它功能齐全,是 Maven 插件创作的一个相当令人印象深刻的示例。

I highly recommend the maven-nar-plugin. I find it superior in many ways to the alternatives. It doesn't require listing out source files, handles multiple OSes and architectures, handles unit and integration tests, and generally follows "the maven way". It introduces a new kind of packaging - the NAR, or "native archive", that contains the artifact you care about (.dll, .so, .a, .exe, etc.) but also metadata, headers, etc. in a way that makes sense.

It does require a bit of up front work to package third-party software up into NARs, but its pretty straightforward. Once they are NARs, you simply use the normal Maven dependency mechanism to link with them, for example:

<dependency>
  <groupId>cppunit</groupId>
  <artifactId>cppunit</artifactId>
  <scope>test</scope>
</dependency>

One drawback is that it does not appear to be actively maintained, but it is full-featured and is a rather impressive example of Maven plugin authoring.

柠檬色的秋千 2024-08-14 00:10:13

在 Maven (Java) 上有一个等价的东西。
我的建议是使用 CMake + CPM 进行构建和 PKG 管理,这是 C++ 世界中使用的最常用工具。
作为 C++ 的替代方案,Gradle 也存在。

有用的链接: https://medium .com/swlh/cpm-an-awesome-dependency-manager-for-c-with-cmake-3c53f4376766

To have an equivalent at Maven (Java).
My advice is to use CMake + CPM for build and PKG management, most commun tools used in C++ world.
As an alternative Gradle exist also for C++.

useful link: https://medium.com/swlh/cpm-an-awesome-dependency-manager-for-c-with-cmake-3c53f4376766

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