DCMTK  Version 3.6.3
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:

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:

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 Mon Feb 5 2018 for DCMTK Version 3.6.3 by Doxygen 1.8.14