Skip to content

Instantly share code, notes, and snippets.

@amir-saniyan
Last active August 4, 2020 16:55
Show Gist options
  • Save amir-saniyan/4cc58960171d7c298484b0aed77019ac to your computer and use it in GitHub Desktop.
Save amir-saniyan/4cc58960171d7c298484b0aed77019ac to your computer and use it in GitHub Desktop.

Build Dlib

Ubuntu Prerequisites

$ sudo apt install build-essential pkg-config cmake libx11-dev

Windows Prerequisites

  • Install MSYS2 (https://www.msys2.org)
  • Open Start Menu > MSYS2 64bit > MSYS2 MSYS and run the following commands:
$ pacman -Syu
$ ########## Close terminal window. ##########
$ pacman -Su
$ pacman -S base-devel
$ pacman -S mingw-w64-i686-toolchain
$ pacman -S mingw-w64-x86_64-toolchain
$ pacman -S mingw-w64-i686-cmake
$ pacman -S mingw-w64-x86_64-cmake
  • To compile 32-bit version: Start Menu > MSYS2 64bit > MSYS2 MinGW 32-bit
  • To compile 64-bit version: Start Menu > MSYS2 64bit > MSYS2 MinGW 64-bit
  • Dependencies:
    • libwinpthread-1.dll
    • libgcc_s_dw2-1.dll (for x86)
    • libgcc_s_seh-1.dll (for x64)
    • ibstdc++-6.dll

Compilation

$ cd dlib-x.y/build
$ cmake \
	-G "MSYS Makefiles" \ # For Windows
	-D CMAKE_BUILD_TYPE=Release \
	-D BUILD_SHARED_LIBS=ON \
	-D USE_SSE2_INSTRUCTIONS=OFF \
	-D USE_SSE4_INSTRUCTIONS=OFF \
	-D USE_AVX_INSTRUCTIONS=ON \
	-D DLIB_GIF_SUPPORT=OFF \
	-D DLIB_JPEG_SUPPORT=ON \
	-D DLIB_PNG_SUPPORT=ON \
	-D DLIB_USE_BLAS=OFF \
	-D DLIB_USE_LAPACK=OFF \
	-D DLIB_USE_CUDA=OFF \
	-D DLIB_NO_GUI_SUPPORT=OFF \
	-D CMAKE_INSTALL_PREFIX=~/dlib \
	..
$ make
$ make install

Using

CMake:

  • FIND_PACKAGE(dlib REQUIRED)
  • TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${dlib_LIBRARIES})
  • This file will define the following variables:
- dlib_LIBRARIES                : The list of all imported targets for dlib modules.
- dlib_INCLUDE_DIRS             : The dlib include directories.
- dlib_VERSION                  : The version of this dlib build.
- dlib_VERSION_MAJOR            : Major version part of this dlib revision.
- dlib_VERSION_MINOR            : Minor version part of this dlib revision.

PKG-CONFIG:

$ pkg-config --cflags --libs dlib-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment