The Library Algorithms API Wrappers Bayesian Nets Compression Containers Graph Tools Image Processing Linear Algebra Machine Learning Metaprogramming Miscellaneous Networking Optimization Parsing Help/Info Examples: C++ Assignment_Learning Base64_Encoder Bayesian_Network Bayesian_Network_From_Disk Bayesian_Network_GUI Bridge BSP Cmd_Line_Parser Compress_Stream Config_File_Reader Custom_Trainers Directory_Navigation Empirical_Kernel_Map Face_Detection FHOG_Feature_Extraction FHOG_Object_Detection Graph_Labeling GUI HTTP_Server Image IO Socket Streams IO Streams Server Kernel_Centroid Kernel_K-Means_Clustering Kernel_Ridge_Regression Kernel_RLS_Filtering Kernel_RLS_Regression KRR_Classification Learning_to_Track Linear_Manifold_Regularizer Logger Logger_Advanced Matrix Matrix_Expressions Member_Function_Pointer Model_Selection Multiclass_Classification Multithreaded_Object Neural_Network Non-Linear Least Squares Numerical_Integration Object_Detector Object_Detector_Advanced One_Class_Classifiers Online_SVM Optimization Parallel_For_Loops Pipe Pipe_2 Quantum_Computing Queue Rank_Features Relevance_Vector_Classification Relevance_Vector_Regression Running_Stats Sequence_Labeling Sequence_Segmentation Sockets Sockstreambuf Sparse_Vectors Std_C++_Allocator Structural_Support_Vector_Machines Support_Vector_Machine Support_Vector_Regression SURF SVM-Rank Threaded_Object Threads Thread_Function Thread_Pool Timer Train_Object_Detector Using_Custom_Kernels XML_Parser Examples: Python Face_Detector Linear_Assignment_Problems Sequence_Segmenter Structural_Support_Vector_Machines SVM-Rank Train_Object_Detector FAQ Home How to compile How to contribute Index Introduction License Python API Suggested Books Current Release Change Log Release Notes Version: 18.7 |
Last Modified: Jun 08, 2013
| # How to compile To use this library all you have to do is extract it somewhere, make sure the folder containing the dlib folder is in your include path, and finally add dlib/all/source.cpp to your project. It is worth noting that most of dlib is "header-only" which means that, in many cases, you don't actually have to build dlib/all/source.cpp into your application. So if you don't get linker errors when you exclude dlib/all/source.cpp from your project then you don't need it. An example makefile that uses this library can be found here: dlib/test/makefile. It is the makefile used to build the regression test suite for this library. There is also a CMake makefile that builds the regression test suite at dlib/test/CMakeLists.txt and another CMake makefile that builds all the example programs at examples/CMakeLists.txt I try to make sure everything compiles fine under Visual Studio .NET 2005 (and above) and gcc (4.1 and above). Again, note that you should not add the dlib folder itself to your compiler's include path. Doing so will cause the build to fail because of name collisions (such as dlib/string.h and string.h from the standard library). Instead you should add the folder that contains the dlib folder to your include search path and then use include statements of the form `#include <dlib/queue.h>`. This will ensure that everything builds correctly. Finally, note that dlib/revision.h defines DLIB_MAJOR_VERSION and DLIB_MINOR_VERSION which are #defines you can use to see what version of dlib you have. # Examples ## Compiling on Any Operating System Using CMake The simplest way to compile the example programs is to use CMake. You can do this by typing the following on the command line.
    cd examples
    mkdir build
    cd build
    cmake ..
    cmake --build . --config Release
Note that you also need to have a C++ compiler installed on your system. There are free C++ compilers for most operating systems. For example, Visual Studio Express is free on Windows and GCC is free and works well on Mac OS X and Linux systems. ## Compiling on Linux From Command Line From within the examples folder, you can compile any of the examples with a single command like so:
    g++ -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp
Note that not all examples require this much work. For example, the svm_ex.cpp example can be compiled with just:
    g++ -O3 -I.. svm_ex.cpp
On non-Linux systems like Solaris, you might have to link to other libraries. For example, I have seen systems where it was also necessary to supply -lnsl or -lsocket options to g++. Additionally, the X11 development library isn't installed on Ubuntu by default. So if you require it and are using Ubuntu you can install it by typing:
    sudo apt-get install libx11-dev
## Compiling on Windows Using GCC The commands for gcc on windows are the same as above but you may also have to link (via the -l option) to the following libraries: gdi32, comctl32, user32, ws2_32, or imm32. However, it's worth pointing out that Visual Studio Express is free and a much better choice for windows development than gcc. ## Compiling on Windows Using Visual Studio All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the folder containing the dlib folder to the #include search path. Then you can compile any example program by adding it to your project. # Preprocessor Directives There are a few preprocessor directives you can supply during the build process to cause the library to build in various optional ways. By default, the library will always do something reasonable, but they are listed here in the event that you need to use them. ### #define ENABLE_ASSERTS Defining this directive causes all the DLIB_ASSERT macros to be active. If you are using visual studio or CMake then ENABLE_ASSERTS will be automatically enabled for you when you compile in debug mode. However, if you are using a different build system then you might have to manually enable it if you want to turn the asserts on. ### #define DLIB_ISO_CPP_ONLY This is a #define directive that you can set to cause the library to exclude all non ISO C++ code (The things in the API wrappers section and any objects that depend on those wrappers). This is useful if you are trying to build on a system that isn't fully supported by the library or if you just decide you don't want any of that stuff compiled into your program for your own reasons. ### #define DLIB_NO_GUI_SUPPORT This is just like the DLIB_ISO_CPP_ONLY option except that it excludes only the GUI part of the library. An example of when you might want to use this would be if you don't need GUI support and you are building on a UNIX platform that doesn't have the X11 headers installed. ### #define NO_MAKEFILE This preprocessor directive causes the dlib headers to pull in all the code that would normally be built in dlib/all/source.cpp. Thus if you #define NO_MAKEFILE you won't have to add dlib/all/source.cpp to your project. The only time this is useful is when your project consists of a single translation unit (i.e. a single cpp file). In this instance NO_MAKEFILE allows you to easily build your project on the command line by saying something like `g++ -DNO_MAKEFILE project.cpp`. But again, this is only for single cpp file projects. If you use NO_MAKEFILE with projects that contain more than one cpp file you will get linker errors about multiply defined symbols. Also note that if you use this macro then the stack trace functionality in the library will be disabled. ### #define DLIB_THREAD_POOL_TIMEOUT <time-in-milliseconds> If you use dlib to create your threads then you receive the benefit of the dlib dynamic thread pool (Note that the dlib::thread_pool object is something else unrelated to this so don't confuse the two). This pool enables dlib to spawn new threads very rapidly since it draws threads back out of its thread pool when the pool isn't empty. Thus, when a thread that was created by dlib ends it actually goes back into the dlib thread pool and waits DLIB_THREAD_POOL_TIMEOUT milliseconds before totally terminating and releasing its resources back to the operating system. The default timeout used by this library is 30,000 milliseconds (30 seconds). You may however change this to whatever you like by defining DLIB_THREAD_POOL_TIMEOUT to some new value.