Pure Programmer
Blue Matrix


Cluster Map

Dependency Management

L1

This page is under construction. Please come back later.

It is often easier to write programs when you don't have to write all the code from scratch. There are a large number of code libraries available, both open source (free) and commercial (paid). Using code libraries written by the community or commercial developers give you a leg up in your coding efforts by making a large library of useful functions and classes available to your program. All we need to do is manage these dependencies and include them in our programs.

C++ doesn't come with a package manager. Typically you can download pre-compiled C++ libraries from the website for that library. You then put these library files in your project folder and link them to your program.

Once your library is installed, you simply add the -l option when you are compiling your program to link to the library. For example to link to the fmt library use:

$ g++ -std=c++17 -w hello.cpp -o hello -lfmt $ ./hello Hello

If your library is implemented using templates as a pure header file, all you need to do is download the .hpp header file and place it in the same folder as your program source. This is the way the Pure Programmer utils library is implemented. Simply download the [[Pure Programmer C++ Utility Templates]].

It doesn't matter whether you installed a precompiled library or are using a pure header library, the way you use the library is the same. In your .cpp source file, simply put an include preprocessor directive at the beginning of your file. For example, to include the Pure Programmer library downloaded above simply add an include for "Utils.hpp":

#include "Utils.hpp"
#include <iostream>
#include <string>
Including Libraries in C++

For libraries that reside in your project directory, you must enclose the header file name in double quotes. For libraries that come with C++ or are installed in your system folders, use the angle brackets instead.

References