类似于 Maven 的 C++ 依赖管理?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1136065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:58:44  来源:igfitidea点击:

Maven-like dependency management for C++?

c++mavenbuilddependency-management

提问by weberste

Say I have a C++ project that is split in several subprojects. The subproject all produce a DLL and different teams of developers work on each of the subproject. Now if I want to build the main project, is there a way to avoid having to build all the subprojects by myself?

假设我有一个 C++ 项目,它分为几个子项目。子项目都生成一个 DLL,不同的开发团队负责每个子项目。现在如果我想构建主项目,有没有办法避免必须自己构建所有子项目?

In short, I'm looking for something that does the dependency management (i.e. for binary files and headers) in a similar way as Maven does for Java.

简而言之,我正在寻找以与 Maven 为 Java 所做的类似的方式进行依赖项管理(即对于二进制文件和头文件)的东西。

In fact, I tried to use Maven for this but this is rather cumbersome because I have to create the packages manually and quite frequently, Maven misses to pick up the most recent changes. Also, running the compilation is a bit of a hack as I have to call NAnt from within Maven (I use NAnt's feature to build Visual Studio solutions directly).

事实上,我尝试为此使用 Maven,但这相当麻烦,因为我必须手动创建包,而且非常频繁,Maven 错过了获取最近的更改。此外,运行编译有点麻烦,因为我必须从 Maven 中调用 NAnt(我使用 NAnt 的功能直接构建 Visual Studio 解决方案)。

Any hints and ideas of how to do this?

有关如何执行此操作的任何提示和想法?

回答by ovanes

Initial Answer: I would suggest using CMake. It is a multi-platform make file generator (generates Visual Studio or Eclipse CDT projects as well).

初始答案:我建议使用 CMake。它是一个多平台的 make 文件生成器(也生成 Visual Studio 或 Eclipse CDT 项目)。

http://www.cmake.org/

http://www.cmake.org/

I did really good experience with it. The best thing I like about it was the ability to produce generic project structure. So you can generically include sub-projects look-up for unit tests etc. without changing the script every time.

我对它的体验非常好。我最喜欢它的是能够生成通用的项目结构。因此,您通常可以包含单元测试等的子项目查找,而无需每次都更改脚本。

They have also lots of modules on how to find pre-installed build libraries, required for the project (like Boost, QT etc.)

他们还有很多关于如何查找项目所需的预安装构建库的模块(如 Boost、QT 等)



Update: In the mean time there was some effort to introduce package management for C++. Some projects worth looking at:

更新:同时,有一些努力为 C++ 引入包管理。一些值得关注的项目:

  • conan.iointegrates with major build tools:
    • CMake
    • Visual Studio
    • Makefile
    • XCode
    • ...
  • cpmbased on CMake (NoteCPM is not being actively maintained.)
  • Buckaroo
  • conan.io与主要构建工具集成:
    • 制作
    • 视觉工作室
    • 生成文件
    • 代码
    • ...
  • cpm基于 CMake(注意CPM 没有得到积极维护。)
  • 巴卡鲁

Noteas pointed out by @RAM in the comments cpm is no longer actively maintained.

请注意@RAM 在评论中指出的 cpm 不再积极维护。

回答by carlos.baez

For the dependency management, it exists a new project (it is a startup company) which is implementing this type of tool: https://github.com/biicode(a C++ dependency manager). You could add your dependencies and it should work.

对于依赖管理,它存在一个正在实现此类工具的新项目(它是一家初创公司):https: //github.com/biicode(C++ 依赖管理器)。您可以添加依赖项,它应该可以工作。

Currently, the project's name is conan.io, they were acquired by JFrog.

目前,该项目的名称是conan.io,它们被JFrog收购。

UPDATE:The project is dead... Unfortunately, it seems the startup couldn't get enough premium paying customers, but the server seems is working fine...

更新:该项目已经死了......不幸的是,这家初创公司似乎无法获得足够的付费客户,但服务器似乎运行良好......

UPDATE2:It seems there is a substitute project: conan.io(thanks @mucaho)

UPDATE2:似乎有一个替代项目:conan.io(感谢@mucaho)

回答by carlosvin

I recommend the following high-level build systems:

我推荐以下高级构建系统:

回答by Rich Seller

If you only want dependency management, try Ivy, it integrates nicely with Ant (and I assume NAnt can do the same based on this blog, which is linked from the Ivy site).

如果你只想要依赖管理,试试Ivy,它与 Ant 很好地集成(我假设 NAnt 可以根据这个博客做同样的事情,它是从 Ivy 站点链接的)。

There is also Byldan, a .Net version of Maven. Don't know how well that will work for you though.

还有Byldan,一个 .Net 版本的 Maven。不知道这对你有多好。

回答by Will

Make and GCC are a great combo for really good dependency checking.

Make 和 GCC 是非常好的依赖关系检查的绝佳组合。

GCC can generate 'make' dependency files automatically (-MD commandline switch), so as to be able to rebuild all sourcefiles that depend upon a given header, for example.

例如,GCC 可以自动生成“make”依赖文件(-MD 命令行开关),以便能够重建所有依赖于给定头文件的源文件。

I have some simple rules that I cut-n-paste into my makefiles:

我有一些简单的规则,我可以将它们剪切-粘贴到我的 makefile 中:

# compile c files   
%.o:    %.c
    ${CC} ${CFLAGS} -c $< -MD -MF $(<:%.c=%.dep) -o $@

# compile c++ files
%.opp:  %.cpp
    ${CPP} ${CPPFLAGS} -c $< -MD -MF $(<:%.cpp=%.dep) -o $@

Now if your object files are declared in say an OBJ_C and an OBJ_CPP list:

现在,如果您的目标文件在 OBJ_C 和 OBJ_CPP 列表中声明:

.PHONY: cleandep
cleandep:
    rm -f $(OBJ_C:%.o=%.dep) $(OBJ_CPP:%.opp=%.dep)

-include $(OBJ_C:%.o=%.dep) $(OBJ_CPP:%.opp=%.dep)

Make can of course track dependencies with other projects and such, e.g. rebuilding a shared libary as necessary, too.

Make当然可以跟踪与其他项目的依赖关系等,例如也可以根据需要重建共享库。

For example, if your other teams always put their latest DLLs on some shared folder:

例如,如果您的其他团队总是将他们最新的 DLL 放在某个共享文件夹中:

myapp: ${SRC_CPP} ${LIB_DIR}other_team.lib
  ...

${LIB_DIR}other_team.lib: /shared_folder/latest/other_team.lib
  cp /shared_folder/latest/other_team.lib ${LIB_DIR}other_team.lib

回答by Martijn Mellens

Edit:

编辑:

Biicode is deprecated

Biicode 已弃用

Alternative: Conan.io

替代方案: Conan.io

回答by Ben Chen

I recommend conan, which I was using these days. It's very powerful to maintain all the dependent libraries and binaries in your project.

我推荐柯南,我这些天正在使用它。维护项目中的所有依赖库和二进制文件非常强大。

回答by KindDragon

You can create NuGet package for used libraries and use NuGet for dependency management.

您可以为使用过的库创建 NuGet 包并使用 NuGet 进行依赖项管理。

See also, NuGet for C++

另请参阅用于 C++ 的 NuGet

回答by oleg.blinnikov

There is a number of tools sitting on top of SCons, providing higher-level functionality similar to that of Autotools which are trying to make the developers life easier (e.g. WAF, SNOCS). Unfortunately, SCons itself has the major drawback - longer compilation time for the large projects.

有许多工具位于 SCons 之上,提供类似于 Autotools 的更高级别的功能,这些工具试图使开发人员的生活更轻松(例如 WAF、SNOCS)。不幸的是,SCons 本身有一个主要缺点——大型项目的编译时间较长。

I can recommend to try out SNOCS(which is a SCons reversed) for those of you looking for an easy dependency management and choosing compilation options in the single command (compiler, x86/x64, Debug/Release, static/shared libraries, test/install targets, etc.).

我可以建议您尝试SNOCS(这是一个 SCons 反转),为那些寻求简单的依赖管理并在单个命令中选择编译选项的人(编译器、x86/x64、调试/发布、静态/共享库、测试/安装目标等)。

SNOCS also tries to tackle the long compilation time problem by storing the projects configuration output in the separate files, which allows the consequent builds to skip configuration phase altogether and go straight to the building phase (last feature is under construction now)

SNOCS 还尝试通过将项目配置输出存储在单独的文件中来解决编译时间长的问题,这允许后续构建完全跳过配置阶段并直接进入构建阶段(最后一个功能正在构建中)

CMake's configuration becomes tedious in a larger solutions, so the build system maintenance takes a large fraction of the developer time. Luckily as Martijn already mentioned there is biicodewhich "uses CMake to generate your project with its dependencies".

CMake 的配置在较大的解决方案中变得乏味,因此构建系统维护占用了开发人员的大部分时间。幸运的是,正如 Martijn 已经提到的,有一个biicode,它“使用 CMake 生成您的项目及其依赖项”。

回答by Buri

Try SCons

尝试SCons

SCons is an Open Source software construction tool—that is, a next-generation build tool. Think of SCons as an improved, cross-platform substitute for the classic Make utility with integrated functionality similar to autoconf/automake and compiler caches such as ccache. In short, SCons is an easier, more reliable and faster way to build software.

SCons 是一种开源软件构建工具,即下一代构建工具。将 SCons 视为经典 Make 实用程序的改进的跨平台替代品,具有类似于 autoconf/automake 和编译器缓存(如 ccache)的集成功能。简而言之,SCons 是一种更简单、更可靠、更快速的软件构建方式。