Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ how to manage dependencies (use libraries from github for example)

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

My question is fairly simple - how should I use lib's 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 ammount of libs they have is pretty small and don't include any what i'm loking for.

So, for example - I want to use nlp lib meta. Seem's like they don't provide any installer file. So I assume I need to get sources from github. Should I compile them and then trying to add compiled files to my project or I need to have 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 colegue will be coding Clion under Linux. And I wan't to realize which is a proper way to managing dependencies in C++ world.

like image 485
silent_coder Avatar asked Sep 26 '16 14:09

silent_coder


People also ask

How do I use dependencies on GitHub?

Under your repository name, click Settings. In the "Security" section of the sidebar, click Code security and analysis. Read the message about granting GitHub read-only access to the repository data to enable the dependency graph, then next to "Dependency Graph", click Enable.

How do I add an external C++ library to my project?

Go to the Project menu. Go to Build Options... In the options dialog, select the Linker Settings tab. Use the Add button to select a library and add it to your project.

How do I add external dependencies in Visual Studio?

Just right click on your project and select properties. There you will get another set of options under 'Configuration Properties' . Go to C/C++ and under that -> General -> Additional Include Directories ( where all the header files of third party is there ).


2 Answers

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.

like image 189
Martin Bonner supports Monica Avatar answered Oct 13 '22 06:10

Martin Bonner supports Monica


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.

like image 38
Paul Fultz II Avatar answered Oct 13 '22 08:10

Paul Fultz II