147

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.

Right leg
  • 16,080
  • 7
  • 48
  • 81
elzi
  • 5,442
  • 7
  • 37
  • 61
  • 9
    `iostream` is standard library header, it must be present of you have C++ compiler installed. If you are missing it, something's wrong with your setup. – n0rd Jan 09 '15 at 18:45
  • 2
    No, the C++ language specification does not require packages nor package managers. There is no concept of packages in the C++ specification. – Thomas Matthews Jan 09 '15 at 18:59
  • 1
    The concept of packaging is usually left to the compiler or IDE. – Thomas Matthews Jan 09 '15 at 19:00
  • 5
    I just started developing in C and have the same background as you have. It is really strange, that public C libraries are not gathered within a central repository. – Benedikt Oct 08 '15 at 21:33
  • I'm surprised nobody has mentioned git submodules or subtrees. 1: [Blog post comparing the two](https://andrey.nering.com.br/2016/git-submodules-vs-subtrees/) 2: [git-scm submodules article](https://git-scm.com/book/en/v2/Git-Tools-Submodules) 3: [old but useful reddit thread comparing approaches for dependencies in C++](https://www.reddit.com/r/cpp/comments/2eiulw/dependency_manager_for_ccmake_projects/) – Benji XVI Mar 19 '17 at 11:57
  • I wanna too! so started project https://github.com/wsjcpp/wsjcpp – sea-kg Mar 26 '20 at 17:22
  • 1
    Look at the comments and interest in this! Obviously this is related to programming and it is not about "opinion" - it requests a list of possibilities so that C++ programmers can use StackOverflow, rather than being forced to Google, to save time when investigating package managers so that they can make up their own minds. Consider the top-voted answer as of the date I write this: It's simply a list of package managers - not giving an opinion about them - to save programmers' time. This question should be re-opened. – Dan Nissenbaum Mar 24 '23 at 15:07

5 Answers5

75

There seem to be a few though I've never used them.

bpt https://github.com/vector-of-bool/dds

cpm http://www.cpm.rocks/

conan https://conan.io/

poac https://github.com/poacpm/poac

pacm http://sourcey.com/pacm/

spack https://spack.io

buckaroo http://buckaroo.pm

hunter https://github.com/ruslo/hunter

vcpkg https://github.com/Microsoft/vcpkg

user3071643
  • 1,405
  • 1
  • 15
  • 18
  • 14
    Has anything changed since 2016? Which package manager is now most used and standardized? What does C++ developers use instead to handle dependencies? – Filip Š Jul 02 '19 at 16:08
  • 11
    Modules will be in c++20 so I would expect a new package manager at that point. – user3071643 Sep 30 '19 at 22:32
  • Thank you, good to know. But how does currently project handle dependencies? I saw some packages which require to manually install dependencies, but I want to know if there are also other options. – Filip Š Oct 01 '19 at 14:21
  • 3
    As of August 2020 cpm appears to be down. The package management solutions in the C++ space definitely leave a lot to be desired. – Regan Koopmans Aug 02 '20 at 08:44
  • 2
    Update: dds is now called bpt and there is a new package manager called [poac](https://github.com/poacpm/poac) – oraqlle Aug 30 '22 at 11:53
55

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!

Community
  • 1
  • 1
pzrq
  • 1,626
  • 1
  • 18
  • 24
  • 2
    `conan` is the only package manager that worked for me. `cmake` also have a `FetchContent` module that can be used like a package manager. `conan` still have some rough edges on the `msys2`/`cygwin` platform (or maybe I don't know how to properly configure it). Unfortunately, conan requires python installation on Windows. – Dilawar Oct 20 '21 at 03:03
35

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.

Jay
  • 1,337
  • 1
  • 17
  • 21
  • 1
    OSX has Homebrew, but this is typically used to download already built software, like MySQL, Apache, Nginx, or things like Node.js or Python. So, this is like linux apt-get – OzzyTheGiant Mar 21 '19 at 13:59
  • 1
    Why do you mention Node? Are you suggesting that if the C++ lib you want to use has a Node wrapper you can install that using npm? – Dana Case Aug 11 '20 at 04:11
  • 1
    @DanaCase Yes, that's exactly what I'm saying. Node.js is sometimes used as the outer shell of a project or application, and the parts that need the most low level control for speed are written in C/C++ or Rust in a dynamic library/shared object. Electron apps are basically Node.js apps with a web browser for UI, and if speed is needed, then either a WASM library or a native dynamic library/shared object is loaded and used from Javascript. To compile your dynamic library/shared object natively: For Rust, you can use Neon, which integrates with Cargo. For C/C++, you can use node-gyp. – Jay Aug 11 '20 at 13:18
  • 1
    To be clear, in npm, the "wrapper" and C/C++/Rust library come to you in source form, usually. That's why when you install Node.js on Windows, it also asks to install a C/C++ compiler to work correctly (the most commonly used native library projects are written in C/C++). – Jay Aug 11 '20 at 13:26
  • [Re: Update 2](https://youtu.be/nLdB1ErncBg) by the Conan developer trolls his own package. – Carel Mar 15 '21 at 16:05
16

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

3

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.

Community
  • 1
  • 1
Brian Bi
  • 111,498
  • 10
  • 176
  • 312
  • I m trying create easy way for fast create c++ project and get something open source code, what I need to c++ project… so started wsjcpp project like a source package manager for c++. Maybe it’s interesting for a people. Here main repo: https://github.com/wsjcpp/wsjcpp – sea-kg Aug 25 '21 at 20:28