DCMTK Version 3.6.8
OFFIS DICOM Toolkit
C++11 support in DCMTK

You may compile DCMTK with C++11 support enabled. This may increase performance since some operations can be performed in a more efficient manner, e.g. utilizing move semantics. To create a C++11 build of DCMTK, you simply need to set the appropriate compiler-flags while building it (e.g. -std=c++11). This will however not enable DCMTK to use available C++11 features that aren't implicitly used by legacy code. This is especially important regarding some C++11 classes DCMTK directly supports, for example:

Since not every compiler supports C++11, legacy implementations for the respective functionality have been created, which are enabled by default.

If you use C++11 in your project, you may want to use the native C++11 classes and features instead, so you don't need to convert your objects to use them with DCMTK. To do so, you need to configure DCMTK to use the C++11 STL, which is described below.

Enabling DCMTK to use C++11

By enabling DCMTK to use C++11, you gain the following advantages:

  • DCMTK will use available C++11 features instead of its only legacy implementations. These are probably more efficient and complete.
  • The enabling of C++11 becomes part of DCMTK's configuration, which allows DCMTK to assist you when checking for API/ABI (in-)compatibility between C++11 and non C++11 builds.

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:

  • GNU C++ Compiler (g++) Version 4.8.1 or later.
  • Clang (clang++) Version 3.3 or later.
  • According to Microsoft documentation, Visual Studio 2019 Version 16.8 (or higher) with Windows SDK 10.0.20348.0 Version 2104 (or higher). DCMTK already allows enabling C++11 for VS 2017 which reportedly also works well.

To enable the C++11 STL, different steps are necessary on CMake and GNU Autoconf, see the appropriate section below:

CMake

Request building with C++11 features by setting the option DCMTK_ENABLE_CXX11 to On, for example via:

cmake ... -DDCMTK_ENABLE_CXX11:BOOL=ON ...

CMake detects the C++11 compilers and knows how to enable C++11 features on Clang, GCC and Intel compilers. You can override the assumed compiler flags (for example to enable C++14 instead) by modifying DCMTK_CXX11_FLAGS, for example:

cmake ... -DDCMTK_ENABLE_CXX11:BOOL=ON -DDCMTK_CXX11_FLAGS=-std=c++14 ...

CMake will then perform basic checks to ensure the compiler is configured correctly and conforms closely enough to C++11 standard. If everything works CMake will print something like this:

-- Checking whether the compiler supports C++11
-- Checking whether the compiler supports C++11 -- yes
-- Info: C++11 features enabled

Unsupported Compilers

If our CMake setup does not know how to enable C++11 on your compiler, it will simply assume that no configuration is required (e.g. for Visual Studio). If this is not appropriate you have to set DCMTK_CXX11_FLAGS manually as mentioned above. If you enable C++11 via DCMTK_ENABLE_CXX11 for an unsupported compiler, CMake will simply set the flags provided via DCMTK_CXX11_FLAGS (if any) and still run the C++11 compatibility test to the compiler conforms closely enough to the C++11 standard for being able to compile DCMTK. If it doesn't, CMake will give an output similar to this one:

-- Checking whether the compiler supports C++11
-- Checking whether the compiler supports C++11 -- no
-- Info: C++11 features disabled

At this point you will not be able to enable C++11 features for the given compiler, since building DCMTK would fail if you did. If you are sure that your compiler supports C++11, you should try setting different flags as DCMTK_CXX11_FLAGS.

GNU Autoconf

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


Generated on Tue Dec 19 2023 for DCMTK Version 3.6.8 by Doxygen 1.9.4