C++: Dlib Installation

C++: Dlib Installation


Dlib can be
installed in two different ways:

<!--1. Using Cmake

Using Cmake is the best way to
compile a C++ program that uses dlib. For example, the following commands will
compile the example programs on any operating system:

cd examples:

mkdir build

cd build

cmake ..

cmake --build . --config Release

On the system, a C++11 compiler must
be installed. For example, GCC is free and effective on Mac OS X and Linux
computers, and Visual Studio is free on Windows. Free C++11 compilers are
available for the majority of operating systems. If more than one compiler or
IDE is installed, the user can instruct CMake using the -G option which one
they want it to use.

CMake is instructed on how to create
examples in the examples/CMakeLists.txt file. Starting with this file and
making any necessary edits will allow the user to develop projects. Using the
cmake-gui or ccmake tool, it can also carry out extra configuration of a cmake
project. For instance, it is suggested to enable either SSE4 or AVX
instructions when using the face detector in dlib because doing so speeds up

Finally, take note that CMake will
automatically produce a 32bit executable when used with Visual Studio. This
implies that the built programmes can only use 2GB of RAM. CMake will need to
produce a 64bit executable in order to prevent this. By using a command like

cmake -G "Visual Studio 14 2015
Win64" -T host=x64 ..

instead of

cmake ..

By executing cmake without any
parameters, the user can view the list of acceptable -G arguments.
Additionally, take note of the -T host=x64 option, which instructs Visual
Studio to permit the compiler to use more RAM than 2GB. That is crucial to
avoid the compiler crashing in specific circumstances due to RAM exhaustion.

<!--2. Without using Cmake

Most of the time, all a user needs
to do to use this library is extract it to a suitable location, make sure the
folder containing the dlib folder is in the inclusion path, and then add
dlib/all/source.cpp to the project.

Be mindful once more that the dlib
subdirectory itself shouldn't be included in the compiler's include path.
Because of name collisions (such as dlib/string.h and string.h from the
standard library), doing this will result in the build failing. Instead, the
user should use include statements of the type #include dlib/queue.h> and
add the folder containing the dlib folder to the include search path. This will
guarantee that everything is built properly.

Also take note that the user must link the application with libjpeg, libpng, and/or libgif in order to operate
with jpeg, png, and gif files using dlib. By specifying the DLIB JPEG SUPPORT,
DLIB PNG SUPPORT, and DLIB GIF SUPPORT preprocessor directives, the user must
additionally inform dlib of this. On UNIX systems, user typically just needs to
add the -ljpeg, -lpng, or -lgif compiler flag (after installing the libraries).
It is less clearly defined on windows. In order to statically build libjpeg and
libpng into the programme if a system-wide version is not present on the
machine, dlib ships with copies of these libraries in the dlib/external
subdirectory. Simply use CMake if the discussion of linking is confusing. This
will be built up entirely by it.

Dlib can also make use of any installed,
optimised versions of the BLAS or LAPACK libraries. Many operations will be
sped up by linking to these libraries. To accomplish this, the user must define
the DLIB USE BLAS and/or DLIB USE LAPACK preprocessor directives, after which
they must link the application with any available BLAS or LAPACK libraries. It
will automatically configure this using CMake.