Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
- name: Configure
run: cmake ${{ github.workspace }}/dlib/test -B build
run: cmake ${{ github.workspace }}/dlib/test -B build -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_EXTENSIONS=OFF
- name: Build just tests
run: cmake --build build --config Release --target dtest --parallel 4
- name: Test
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Dlib is a modern C++ toolkit containing machine learning algorithms and tools fo

## Compiling dlib C++ example programs

Go into the examples folder and type:
You need a C++17 compiler and CMake. Go into the examples folder and type:

```bash
mkdir build; cd build; cmake .. ; cmake --build .
Expand All @@ -21,9 +21,9 @@ mkdir build; cd build; cmake .. -DUSE_AVX_INSTRUCTIONS=1; cmake --build .

Doing so will make some things run faster.

Finally, Visual Studio users should usually do everything in 64bit mode. By default Visual Studio is 32bit, both in its outputs and its own execution, so you have to explicitly tell it to use 64bits. Since it's not the 1990s anymore you probably want to use 64bits. Do that with a cmake invocation like this:
Visual Studio users can explicitly select a 64bit target and compiler with a CMake invocation like this:
```bash
cmake .. -G "Visual Studio 14 2015 Win64" -T host=x64
cmake .. -G "Visual Studio 17 2022" -A x64 -T host=x64
```

## Compiling your own C++ programs that use dlib
Expand Down
7 changes: 5 additions & 2 deletions dlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,13 @@ if (NOT TARGET dlib)
add_library(dlib_all_source_cpp STATIC all/source.cpp)
target_link_libraries(dlib_all_source_cpp dlib)
target_compile_options(dlib_all_source_cpp PUBLIC ${active_preprocessor_switches})
target_compile_features(dlib_all_source_cpp PUBLIC cxx_std_14)
target_compile_features(dlib_all_source_cpp PUBLIC cxx_std_17)
endif()

target_compile_features(dlib PUBLIC cxx_std_14)
target_compile_features(dlib PUBLIC cxx_std_17)
if (DLIB_USE_CUDA)
target_compile_features(dlib PRIVATE cuda_std_17)
endif()
# Build-tree clients share dlib's compiler, so forward the options detected
# above to them. Do not put those options in the installed target, where
# dlibConfig.cmake recreates them for the consuming compiler's frontend.
Expand Down
16 changes: 7 additions & 9 deletions dlib/algs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

// this file contains miscellaneous stuff

// Give people who forget the -std=c++14 option a reminder
#if (defined(__GNUC__) && ((__GNUC__ >= 5 && __GNUC_MINOR__ >= 0) || (__GNUC__ > 5))) || \
(defined(__clang__) && ((__clang_major__ >= 3 && __clang_minor__ >= 4) || (__clang_major__ >= 3)))
#if __cplusplus < 201402L
#error "Dlib requires C++14 support. Give your compiler the -std=c++14 option to enable it."
// Give people who forget to enable C++17 a reminder.
#if defined(_MSC_VER)
// MSVC only updates __cplusplus when /Zc:__cplusplus is enabled.
#if !defined(_MSVC_LANG) || _MSVC_LANG < 201703L
#error "Dlib requires C++17 support. Give your compiler the /std:c++17 option to enable it."
#endif
#elif __cplusplus < 201703L
#error "Dlib requires C++17 support. Give your compiler the -std=c++17 option to enable it."
#endif

#if defined __NVCC__
Expand All @@ -32,10 +34,6 @@

#ifdef _MSC_VER

#if _MSC_VER < 1900
#error "dlib versions newer than v19.1 use C++11 and therefore require Visual Studio 2015 or newer."
#endif

// Disable the following warnings for Visual Studio

// this is to disable the "'this' : used in base member initializer list"
Expand Down
2 changes: 1 addition & 1 deletion dlib/java/cmake_swig_jni
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${binary_dir_name}")

set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/swig.i PROPERTIES CPLUSPLUS ON)
swig_add_module(${output_library_name} java ${CMAKE_CURRENT_BINARY_DIR}/swig.i ${source_files})
target_compile_features(${output_library_name} PUBLIC cxx_std_14)
target_compile_features(${output_library_name} PUBLIC cxx_std_17)

include_directories(${JNI_INCLUDE_DIRS})
swig_link_libraries(${output_library_name} ${additional_link_libraries})
Expand Down
2 changes: 1 addition & 1 deletion dlib/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ namespace dlib
//when deserializing unique_ptr, this is fresh state, so reset the pointers, even if item is non-empty
bool is_non_empty;
deserialize(is_non_empty, in);
item.reset(is_non_empty ? new T() : nullptr); //can't use make_unique since dlib does not use C++14 as a minimum requirement.
item.reset(is_non_empty ? new T() : nullptr);

if (is_non_empty)
deserialize(*item, in);
Expand Down
12 changes: 6 additions & 6 deletions dlib/test/WINDOWS_build_and_run_all_unit_tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ echo testing python >> test_log.txt
rmdir /S /Q build_python
mkdir build_python
cd build_python
cmake -G "Visual Studio 14 2015 Win64" -T host=x64 ../../../tools/python
cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 ../../../tools/python
cmake --build . --config Release || exit /B
ping 127.0.0.1 -n 5 -w 1000 > null
cd ..



echo testing vc2015 >> test_log.txt
rmdir /S /Q build_vc2015_64
mkdir build_vc2015_64
cd build_vc2015_64
cmake -G "Visual Studio 14 2015 Win64" -T host=x64 ..
echo testing vc2022 >> test_log.txt
rmdir /S /Q build_vc2022_64
mkdir build_vc2022_64
cd build_vc2022_64
cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 ..
cmake --build . --config Release || exit /B
ping 127.0.0.1 -n 5 -w 1000 > null
cmake --build . --config Debug || exit /B
Expand Down
2 changes: 1 addition & 1 deletion dlib/test/constexpr_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ namespace
public:
constexpr_if_test (
) : tester ("test_constexpr_if",
"Runs tests on the C++14 approximation of C++17 if constexpr() statements but better.")
"Runs tests on dlib's compile time dispatch utilities.")
{}

void perform_test (
Expand Down
2 changes: 1 addition & 1 deletion dlib/test/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TARGET = dtest

# these are the compile time flags passed to gcc
CXXFLAGS ?= -ggdb -Wall
CPPFLAGS ?= -std=c++14 -DDEBUG -DDLIB_NO_GUI_SUPPORT -I../..
CPPFLAGS ?= -std=c++17 -DDEBUG -DDLIB_NO_GUI_SUPPORT -I../..

# These are the link time flags passed to gcc
LFLAGS = -lpthread -lnsl
Expand Down
18 changes: 9 additions & 9 deletions docs/docs/compile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from github, go to the base folder of the dlib repository,
and run <tt>python setup.py install</tt>. Once either of these commands
finishes running you are ready to use dlib from Python. Note
that you need to have CMake and a working C++ compiler
that you need to have CMake and a working C++17 compiler
installed for this to work.
</p>

Expand Down Expand Up @@ -53,7 +53,7 @@ cd build
cmake ..
cmake --build . --config Release
</code_box>
Note that you need to have a C++14 compiler installed on your system. There are free C++14 compilers
Note that you need to have a C++17 compiler installed on your system. There are free C++17 compilers
for most operating systems. For example, Visual Studio is free on Windows and GCC is free and
works well on Mac OS X and Linux systems. If you have multiple compilers/IDEs installed then you can
tell CMake which one you want it to use via the -G option.
Expand All @@ -65,10 +65,9 @@ tell CMake which one you want it to use via the -G option.
makes it run much faster (also see <a href="faq.html#Whyisdlibslow">this FAQ</a>).
</p>
<p>
Finally, note that when using Visual Studio, CMake will by default generate a 32bit executable.
This means the programs you compile will only be able to use 2GB of RAM. To avoid this, you need
to tell CMake to generate a 64bit executable. You do this by using a command like
<code_box>cmake -G "Visual Studio 14 2015 Win64" -T host=x64 ..</code_box> instead of <code_box>cmake ..</code_box>
When using Visual Studio, select a 64bit target to avoid the memory limits of 32bit executables.
You can do this by using a command like
<code_box>cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 ..</code_box> instead of <code_box>cmake ..</code_box>
You can see the list of valid arguments to <tt>-G</tt> by running <tt>cmake</tt> with no options. Note also the <tt>-T host=x64</tt>
option, which tells Visual Studio to let the compiler use more than 2GB of RAM. That is important if you don't want the compiler to
crash from running out of RAM in some situations.
Expand Down Expand Up @@ -119,7 +118,7 @@ tell CMake which one you want it to use via the -G option.
<h3>Compiling on Linux From Command Line</h3>
From within the examples folder, you can compile nearly all of the examples with a single command like so:
<code_box>
g++ -std=c++14 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp
g++ -std=c++17 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp
</code_box>

On non-Linux systems like Solaris, you might have to link to other libraries. For example, I have seen systems
Expand All @@ -136,9 +135,10 @@ sudo apt-get install libx11-dev
(via the -l option) to the following libraries: gdi32, comctl32, user32, winmm, ws2_32, or imm32.
</p>

<h3>Compiling on Windows Using Visual Studio 2015 or Newer</h3>
<h3>Compiling on Windows Using Visual Studio</h3>
<p>
All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the
Create an empty console project and enable C++17 with <tt>/std:c++17</tt>.
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.
</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/containers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@
<spec_file>dlib/optional.h</spec_file>
<description>
This is a standard's compliant backport of <a href="https://en.cppreference.com/w/cpp/utility/optional">std::optional</a>
that works with C++14. It includes C++23 monadic interfaces
that works with C++17. It includes C++23 monadic interfaces
</description>
</component>

Expand Down
22 changes: 4 additions & 18 deletions docs/docs/faq.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@

<question text="How can I use dlib in Visual Studio?">
<p>
First, note that you need a version of Visual Studio with decent
C++11 support. This means you need Visual Studio 2015 or newer.
First, note that you need a version of Visual Studio with C++17 support.
Enable it with <tt>/std:c++17</tt>, or use CMake to select it automatically.
</p>
There are instructions on the <a href="compile.html">How to Compile</a> page.
If you do not understand the instructions in the "<b>Compiling on Windows Using Visual Studio</b>" section
Expand Down Expand Up @@ -554,22 +554,8 @@ cross_validate_trainer_threaded(trainer,

<questions group="Deep Learning">
<question text="Why can't I use the DNN module with Visual Studio?">
You can, but you need to use Visual Studio 2015 Update 3 or newer since prior versions
had bad C++11 support. To make this as confusing as possible,
Microsoft has released multiple different versions of "Visual Studio
2015 Update 3". As of October 2016, the version available from the
Microsoft web page has good enough C++11 support to compile the DNN
tools in dlib. So make sure you have a version no older than October
2016.
<p>
To make this even more complicated, Visual Studio 2017 had
regressions in its C++11 support. So all versions of Visual Studio
2017 prior to December 2017 would just hang if you tried to compile
the DNN examples. Happily, the newest versions of Visual Studio
2017 appear to have good C++11 support and will compile the DNN
codes without any issue. So make sure your Visual Studio is
fully updated.
</p>
You can, but you need a version of Visual Studio with C++17 support.
Keep Visual Studio fully updated and use CMake to enable the required compiler options.
<p>
Finally, it should be noted that you should give the <tt>-T host=x64</tt>
cmake option when generating a Visual Studio project. If you don't
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/metaprogramming.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ or you can omit the error message and call it like:
<file>dlib/constexpr_if.h</file>
<spec_file link="true">dlib/constexpr_if.h</spec_file>
<description>
This function allows you to do compile time dispatch similar to what you can do with constexpr if in C++17, but only requires a C++14 compiler.
This function allows you to do compile time dispatch similar to what you can do with if constexpr in C++17.
</description>

</component>
Expand Down
13 changes: 12 additions & 1 deletion docs/docs/release_notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
<!-- ************************************************************************************** -->

<current>
New Features and Improvements:

Non-Backwards Compatible Changes:
- Dlib now requires C++17.

Bug fixes:
</current>

<!-- ************************************************************************************** -->

<old name="20.0" date="May 27, 2025">
New Features and Improvements:
- Machine Learning
- Added auto_train_multiclass_svm_linear_classifier(), a tool that trains a multiclass
Expand Down Expand Up @@ -69,7 +80,7 @@ Bug fixes:
- Fix pixel saturation in interpolate_quadratic (PR #2806)
- Fix convolution backward filter cache issue when using cudnn 7 and above (PR #2828)
- Fix a bug in the gradient computation code for the layer_normalize layer.
</current>
</old>

<!-- ************************************************************************************** -->

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
--no USE_AVX_INSTRUCTIONS: will set -DUSE_AVX_INSTRUCTIONS=no
Additional options:
--compiler-flags: pass flags onto the compiler, e.g. --compiler-flags "-Os -Wall" passes -Os -Wall onto GCC.
-G: Set the CMake generator. E.g. -G "Visual Studio 14 2015"
-G: Set the CMake generator. E.g. -G "Visual Studio 17 2022"
--clean: delete any previous build folders and rebuild. You should do this if you change any build options
by setting --compiler-flags or --no since the last time you ran a build. This will
ensure the changes take effect.
Expand Down
Loading