Does C++ have a package manager like npm, pip, gem, etc?

C++

C++ Problem Overview


Just wondering the best way to install cpp packages. My background is in JS/Ruby/etc, so it seems so weird there's no cpm or the like. What am I missing? I assume it's not this simple...

For an example, I can't even run a .cpp file with #include <iostream> as I get fatal error: 'iostream' file not found

Edit for clarity: iostream was a bad example, my system config was wonked back when I wrote this. Replace it in your imagination with a non-standard library.

C++ Solutions


Solution 1 - C++

Solution 2 - C++

Conan is the clear winner today based on its 36+ GitHub contributors and the fact I found their Getting Started documentation to be easy enough to get working. It's MIT licensed too.

Conan's documentation even compares it to biicode which I was surprised wasn't mentioned in other answers, but biicode seems to be abandoned much like cpm.

pacm has some activity but is LGPL which may be an issue for some projects.

This builds on user3071643's answer, thanks!

Solution 3 - C++

No, there certainly isn't an official package manager for C/C++, but I'll give you a few suggestions to hopefully make your days better.

First, I would suggest investigating CMake or GENie for ways of incorporating libraries in your build system in an extensible and cross-platform way. However, they both assume that you have libraries that are in an "easy to find" place or that they have the same build system as your project. There are ways to teach both how to find libraries that you need. All other solutions are platform specific.

If you have Node.js or Haxe in your project, then both npm and haxelib do have ways that you can use C++ (in a precompiled dll/so form) from JavaScript or Haxe respectively, but that's a big, and probably wrong, assumption that you'd be using Node.js or Haxe in a project that really needs the benefits that C/C++ can provide.

For the Microsoft world, I believe that NuGet has some C++ libraries, although it's limited in its platform support to Visual Studio, and probably Windows, but it probably best fits what you mean by "package system" given your examples (assuming that you meant that cpm was a C Package Manager in the way that npm is Node Package Manager).

For the Linux world, technically, rpm, yum, and apt-get do function as C/C++ development package managers just as much as a system package manager, but unlike npm, you must always install packages globally, but given that your app, if it's a Linux app, would likely be in a package on one or more of these managers, and packages have a dependency list embedded in them, it's not much of a problem.

For the macOS/iOS world there's CocoaPods, but, like, NuGet, you're locked-in to the Apple platform. There is always MacPorts, if you are happy with the Linux-style package manager as a dev package manager, as described in the previous paragraph.

I want this npm, local install, sort of functionality cross-platform as well, but since C/C++ is used on so many platforms (all of them?), and C/C++ programmers, like myself, tend to roll their own... everything, which keeps us all (unnecessarily?) busy, there hasn't been much of a push for making such a project, which is a shame. Perhaps, you should make one? It would certainly make my days better.

UPDATE

Conan is the C/C++ package manager that we've all been wanting. It has both local and global servers, so it's good for both business and open source packages. It's young, and its global repository doesn't have very many packages. We should all work to add packages to it!

UPDATE 2

I have found that vcpkg has been very useful for Windows and Android. If you can't get over the fact that Conan.io is written in Python, then it might be worth a look.

Also, although it mandates that you use it for yourself and all of your dependencies, I believe that Build 2 should be the ultimate winner in a few years, but as of the time of writing, it's still upcoming.

Solution 4 - C++

The other answers have mentioned the competing solutions, but I thought I would add my experiences. I did some research into package managers and build systems for $WORK. We were greenfield so anything was on the table. These are my findings, YMMV.

Conan

Claims to support every build system but you need to write these Python scripts to tell Conan how your build works. Lots of magic, and easy to misconfigure. You also need to manage remotes, local remotes, etc. using conan create. We wanted something simple and this put me off. IDE integration did not work reliably (due to the Python scripts). I asked about reproducible builds and they said it is as reproducible as you want to make it. So it is not really reproducible.

https://conan.io/

Hunter

All packages are defined inside a single repository. You need to fork to add packages. Everything is driven by CMake. We want to deprecate CMake internally due to poor syntax, non-reproducible builds, and all the other issues you probably know already. Hunter offers reproducible installations of packages because you put Hunter in source-control, which is excellent.

https://github.com/ruslo/hunter

Buckaroo

Opinionated but simplest solution. No need to manage remotes or forks of package lists since all packages are just Git repos. We use GitHub private so this was a plus for us. We were a bit hesitant about using Buck build system, which they require. Turns out the Buck gets most things right (I used and liked Meson & Bazel in the past), and writing Buck files was less work than integrating CMake projects anyway. Also, and this was big for us, Buckaroo actually supports Java too. Maven support was hacky though. We were able to create iOS and Android builds from a single build tool / package manager. Documentation is poor but they were responsive to my emails. Needs more packages.

https://buckaroo.pm/

VCPKG

Similar to Hunter but from Microsoft. They don't have older versions of packages which might be a problem. Again everything is done in CMake, so builds get more complex and slower over time. I think VCPKG has the most packages of all solutions.

https://github.com/Microsoft/vcpkg

Solution 5 - C++

No, there's no package manager for C++ libraries. There are various ways to install C++ libraries, as with any other software: through your operating system's package manager, by building from a source tarball, or, in the case of proprietary software, by running some installation program.

Note that if #include <iostream> doesn't work, then your compiler or development environment is simply not installed correctly. I believe Super User is the site where you can ask for help with that sort of thing.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionelziView Question on Stackoverflow
Solution 1 - C++user3071643View Answer on Stackoverflow
Solution 2 - C++pzrqView Answer on Stackoverflow
Solution 3 - C++JayView Answer on Stackoverflow
Solution 4 - C++undefined_behavior20View Answer on Stackoverflow
Solution 5 - C++Brian BiView Answer on Stackoverflow