42

I'm very new to C++ world, so please, sorry for such a dummy question. I googled a little, but wasn't able to find a proper answer.

My question is fairly simple - how should I use libraries in C++ world. For example in Java - there is maven and gradle for this task. In Python - I use pip. In javascript npm and bower do all the stuff. In C# you use nuget or just adding DLL lib to your project. But looks like in C++ things isn't such easy.

I found a tool, called conan but amount of libraries they have is pretty small and does not include any what I'm looking for.

So, for example - I want to use nlp lib meta but it seems like they don't provide any installer files. So I assume I need to get sources from Github. Should I compile them and then try to add the compiled files to my project or do I need to have a lib folder in my project, and put meta's sources in those folder and after operate with meta's sources as they are in my project?


My question isn't about how to install specific meta lib, but more from the source management point of view. If I use Visual Studio on Windows for example, but my colleague will be coding Clion under Linux. And I don't know the proper way of managing dependencies in C++ world.

Bunny
  • 1,180
  • 8
  • 22
silent_coder
  • 6,222
  • 14
  • 47
  • 91
  • The library you linked seems to have a rather extensive setup guide for a variety of platforms. Did you try following that? – Baum mit Augen Sep 26 '16 at 14:15
  • Yes, but their guide is mostly for using lib as standalone tool, but I need to reference it in code, so my question isn't about how to install specific lib, but rather how to deal with libs in sense of source management in project. – silent_coder Sep 26 '16 at 14:17
  • 2
    The C++ community generally lacks a ubiquitous package manager, unless you can find that library in one of those managers that you have found, you download the code and build it yourself. – Niall Sep 26 '16 at 14:17
  • What is your build environment? What have you tried so far? – rocambille Sep 26 '16 at 14:20

7 Answers7

13

C++ doesn't have anything like pip or npm/bower. I don't know if maven or gradle can be persuaded to handle C++ libraries.

In general, you are going to have to end up with

  • Header files in a directory somewhere
  • library files (either static libraries, or DLLs/shared objects). If the library is a header-only library like some of the boost libraries, then you won't need this.

You get hold of the library files, either by building them on your machine (typical for open source projects, and projects aimed at Linux platforms), or by downloading the pre-compiled binaries (typical for Windows libraries, particularly paid-for).

Hopefully, the instructions for building the library will be included on the library website. As noted in the comments, 'meta' seems to be quite good at that.

When you try to compile with the library, you may need a command line option (eg -I) to specify the directory containing the header files, and you may need a linker option (eg -l) to tell the linker to link against your library.

9

Cget will install any package that uses standard cmake, and works for linux and windows. It has shorten syntax for getting packages directly from github(such as cget install google/googletest).

In addition, dependencies can be automatically downloaded as well by listing them in a requirements.txt file.

There is also recipes for installing non-cmake packages and the repository here has over 300 libraries(and growing). So you can install curl with just cget install pfultz2/cget-recipes curl.

Paul Fultz II
  • 17,682
  • 13
  • 62
  • 59
  • can we use cget to install packages into some sort of staging folder? Like for example the python venv? – Slava Aug 17 '23 at 14:52
7

C++ sadly has no package manager for libraries. Some are out there and try to be one which are still small and scattered though (like conan).

In linux you have some "-dev" packages you can install but they are also not "all".

You most likely end up downloading them yourself. Next though is you have the problem of integrating those libraries. You have different build systems per operating system so you have to see how you build c++ files.

Like in windows with Visual studio you have to get a visual studio project or a nmake compatible makefile to build the libraries and then add them to your project. Same with linux makefiles.

There are several build frameworks who are higher level like cmake. The example you have in your post also works with CMake. So integrating that one into a cmake build environment would be easier but this only applies for other libraries also trying to use/integrate cmake build environments to it (e.g. boost / qt is doing this).

Yeah these are some thoughts to this. Sadly there won't be an easy/definitive answer to this because there is no real central c++ packet repository which is also integrated into a build system.

Hayt
  • 5,210
  • 30
  • 37
2

It appears to me that the Crascit/DownloadProject could be of help in your situation. It provides CMake plugins for downloading projects from a git repository by specifying tags, etc. Then you can use add_custom_target to run commands you need to have the project built.

Max Levy
  • 384
  • 4
  • 12
0

There are a number of popular C++ released via nuget packages. You can search on the gallery for them, usually using the native or c++ tags. Obviously you need a nuget manager for your OS, and I'm pretty sure that the C++ nuget packages rely on MSBuild for a lot of the grunt work, so you may have trouble getting a non-Visual Studio oriented setup to work nicely.

Also Gradle actually does have some support for native dependencies as well. I had a look at little while ago but the work on it was curtailed because the support for VS 2015 was lacking.

Dennis
  • 3,683
  • 1
  • 21
  • 43
0

I recommend vcpkg for cross platform development. It has a number of IDE integrations. GitHub project is here.

I do cross platform development using tools like CMake, Visual Studio, WSL. vcpkg was incredibly helpful.

kovac
  • 4,945
  • 9
  • 47
  • 90
0

I started new project... in cureent time it's just "source package manager" you can provide some source code on github and then it will be just copy to you project (based on cmake + auto generating cmake files)

So links here: https://github.com/wsjcpp/wsjcpp

sea-kg
  • 317
  • 2
  • 5