113

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?

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.

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).

Any hints and ideas of how to do this?

B Faley
  • 17,120
  • 43
  • 133
  • 223
weberste
  • 1,884
  • 2
  • 17
  • 12
  • The problem when using make is that I have to build everything at least once and therefore also need the source files for the dependencies. Especially, when rebuilding dependent libraries, it can be very time consuming and severly effect productivity. Or am I missing something? – weberste Jul 16 '09 at 08:54
  • 6
    This seems like a useful question. Maybe this question can be ported to another site that is more welcoming to these questions? I'm looking for best practices for c++ dependency management. – simgineer Nov 15 '18 at 19:39
  • This is about 10 years late so there are 3 possibilities here: you're misusing `maven`, you're missing the entire point to `maven`, or 10 years ago when I wasn't using `maven` for C++ it was far less useful for C++. I can't speak for 2009, but in recent years from experience, `maven` is exactly what you would use for the problem you're describing. It does exactly what you want, and quite efficiently and well, and doesn't do the negative things you claim it does. Anyone reading this in 2019 or later should strongly consider using `maven` for this purpose. – searchengine27 Nov 20 '19 at 14:33

12 Answers12

43

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

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.)


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

  • conan.io integrates with major build tools:
    • CMake
    • Visual Studio
    • Makefile
    • XCode
    • ...
  • cpm based on CMake (Note CPM is not being actively maintained.)
  • Buckaroo

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

ovanes
  • 5,483
  • 2
  • 34
  • 60
  • 8
    I used CMake a few months back and indeed, checking for pre installed libraries worked very nicely. However, other binary dependencies (i.e. the ones coming from my subprojects) could not be managed easily. Am I missing something? – weberste Jul 20 '09 at 13:06
  • 3
    @weberste, Actually there is no maven like tool for C/C++. Developers try to handle dependency management with apt-get like tool. – SunnyShah Feb 02 '15 at 15:06
  • 1
    cpm is not actively maintained and has been dead since early 2015. – RAM Aug 03 '18 at 10:24
  • @RAM: thanks for pointing that out. I've added a note in the post with reference to you. – ovanes Aug 04 '18 at 23:06
  • 2
    CMake is a build system with limited ability to find dependencies. It is not a dependency manager in the sense of NPM, Cargo, etc. – sdgfsdh Mar 01 '19 at 09:16
18

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.

Currently, the project's name is conan.io, they were acquired by 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)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
carlos.baez
  • 1,063
  • 2
  • 11
  • 31
  • I can remove the link.. the project was closed, now it is conan.io – carlos.baez Apr 24 '20 at 19:47
  • Thanks for the update! I'm mostly just looking out of curiosity, it looks like it's still possible to poke around on their github for the [documentation](https://github.com/biicode/docs/blob/master/c%2B%2B/gettingstarted.rst); it's probably not as nice as what was on the website at one point but I guess it's better than nothing. Just wondering, is conan.io just a rebrand or is it a totally different product? – jrh Apr 24 '20 at 20:23
  • 1
    Not a rebrand but a completely new project from scratch with all the lessons learned: completely open source, fully decentralized with a server in-house, supports all build-systems, manage binaries. – drodri Apr 26 '20 at 19:58
8

I recommend the following high-level build systems:

carlosvin
  • 979
  • 9
  • 22
  • Maven Nar plugin getting good support. I used it and I like so far. However you need to understand that Maven is not good for a mono repo. Most C++ solution needs an Mono repo handle share libraries and such. – Hans Apr 05 '18 at 14:39
5

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).

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

Rich Seller
  • 83,208
  • 23
  • 172
  • 177
3

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

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.

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

# 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:

.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.

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

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
Will
  • 73,905
  • 40
  • 169
  • 246
  • see my comment attached to the question regarding my concerns with this solution – weberste Jul 16 '09 at 08:55
  • If a target is dependent on another file e.g. your executable is dependent on a shared library, you can have a rule for that shared library that makes sure your copy of the library is up-to-date without needing the source, e.g. by simply fetching the latest copy from a particular location or from executing some version control update or such. – Will Jul 16 '09 at 09:54
  • `${CC} ${CFLAGS} -c $< -MD -MF $(<:%.c=%.dep) -o $@` I had a hard time parsing out all these Make symbols, it looks like this resolves to something like `g++ -c main.cc -MD -MF test` if you want to run it standalone at command line, and it puts the results in a file named 'test'. – jrh Apr 24 '20 at 20:39
3

Edit:

Biicode is deprecated

Alternative: Conan.io

Martijn Mellens
  • 520
  • 7
  • 25
  • 3
    Biicode [is dead](https://www.reddit.com/r/cpp/comments/3h8o2r/biicode_c_dependency_manager_has_gone_out_of/). Successor looks to be [Conan.io](https://www.reddit.com/r/cpp/comments/3v05s9/conan_a_cc_package_manager/). – mucaho Mar 28 '16 at 22:57
2

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

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
Ben Chen
  • 119
  • 1
  • 3
1

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

See also, NuGet for C++

KindDragon
  • 6,558
  • 4
  • 47
  • 75
0

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.

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 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)

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 biicode which "uses CMake to generate your project with its dependencies".

-1

Try 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.

Buri
  • 7
  • 1
-5

I recommend to use the mother of all build dependency systems: make.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • I use this extensively. GCC can make dependency files that 'make' can eat. Enough for another answer, perhaps... – Will Jul 16 '09 at 08:45
  • 8
    make is actually what everybody wants to avoid/replace by looking at build -automation- systems – chila Mar 26 '12 at 18:15
-6

Try scons, you will be hooked. Make is outdated, difficult and expensive to maintain.

piotr
  • 5,657
  • 1
  • 35
  • 60
  • I had a look at Scons but did not find a way to manage binary dependencies. Do you have an example for this? – weberste Jul 20 '09 at 13:05
  • 1
    Since scons is python, you can code whatever you want to manage your binary dependencies quite easily. Perhaps having an "SConscript" in the directory of your binary dependencies also helps. I'm not sure what are your requirements here tough. Pedro. – piotr Jul 21 '09 at 05:14
  • 17
    So you're suggesting a tool based on "I'm not sure what you need, but you can program it yourself in Python". Why do you need scons then? – jalf Aug 10 '11 at 11:05