DCMTK
Version 3.6.9
OFFIS DICOM Toolkit
|
Per default, DCMTK is compiled with C++11 support enabled (via CMAKE_CXX_STANDARD
set to 11). This usually increases performance since some operations can be performed in a more efficient manner, e.g. utilizing move semantics.
Later C++ standards can be enabled using the CMAKE_CXX_STANDARD
setting. DCMTK's INSTALL file describes the available C++ standard versions that are known to work for the given DCMTK version.
DCMTK can still be compiled using a C++98 compiler. However, C++98 support will be be dropped in the future.
While some features like move semantics are automatically enabled in legacy code when compiling with C++11 enabled, modern C++ STL classes like std::unique_ptr must be used explicitly.
Since DCMTK does not require a C++11-aware compiler (yet), the toolkit comes with some wrapper classes for some of these STL features. Each wrapper class either directly maps to the respective C++11 feature (if made available, see below) or otherwise implements a C++98 fallback solution. For example, the following C++11 STL classes are implemented that way:
If you want to ensure that DCMTK uses the STL versions of these classes, there is an additional flag (besides enabling the related C++ version) to be set during CMake configuration:
Enabling the flag DCMTK_ENABLE_STL
will ensure that whenever possible (i.e. supported correctly by the compiler) the STL version of a class is preferred over the fallback implementation.
There are several other flags in order to fine-tune this behavior:
Per default, those flags are set to "INFERRED", meaning that they take over the setting of DCMTK_ENABLE_STL
. However, if you just want to enable or disable certain features (i.e. deviate from DCMTK_ENABLE_STL
), you can set each of them explicitly to "ON" or "OFF".
By compiling with C++11 or later and enabling the STL, you gain the following advantages:
Trying to include a DCMTK build with C++11-enabled from a non C++11 environment will give you the following error message:
DCMTK was configured to use C++11 features, but your compiler does not or was not configured to provide them.
To reduce DCMTK's implementation complexity, C++11 shall only be used if your compiler conforms closely to the C++11 standard. As far as we know, this is currently true for the following compilers:
When compiling with C++11 or later, CMake will then perform basic checks to ensure the compiler is configured correctly and conforms closely enough to all modern C++ standards up to the selected standard version.
Below is a CMake output when (successfully) setting CMAKE_CXX_STANDARD
to 14:
... -- Checking whether the compiler supports C++11 -- Checking whether the compiler supports C++11 -- yes -- Checking whether the compiler supports C++14 -- Checking whether the compiler supports C++14 -- yes ...
Our GNU Autoconf setup understands the switches --enable-cxx11
, and --disable-cxx11
that may be used to configure DCMTK to use C++11 features. If you run
configure --enable-cxx11
our Autoconf script will try to determine the required compiler flags for enabling C++11 features (if any) and perform configuration tests to ensure the compiler conforms closely enough to the C++11 standard. If everything works it will give you an output similar to this one:
checking whether to enable C++11 support... checking whether c++ supports C++11 features by default... no checking whether c++ supports C++11 features with -std=c++11... yes checking whether to enable C++11 support... yes
Otherwise, it will still disable C++11 features with an output like this:
checking whether to enable C++11 support... checking whether c++ supports C++11 features by default... no checking whether c++ supports C++11 features with -std=c++11... no checking whether to enable C++11 support... no
There are further switches that enable STL features, comparable to the CMake configuration described above:
--enable-stl use C++ STL --disable-stl do not use C++ STL (default) --enable-stl-vector use C++ STL vector --disable-stl-vector do not use C++ STL vector --enable-stl-algorithm use C++ STL algorithm --disable-stl-algorithm do not use C++ STL algorithm ....
Support for setting C++ versions later than C++11 is not yet available in DCMTK's Autoconf settings.