C++11 support with Visual Studio 15.7 Preview 3

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
mespak
Posts: 9
Joined: Thu, 2018-02-15, 16:59

C++11 support with Visual Studio 15.7 Preview 3

#1 Post by mespak »

This is the first Visual Studio release that officially supports C++11 (and later standards, too), and that defines the "__cplusplus" macro accordingly. Previous versions set this macro to an archaic version number, even if they provided more or less complete C++11 support, and the /std=c++11 option was used.

So, finally, DCMTK can be compiled with C++11 and STL support on Windows, without any hack (e.g. disabling the compiler checks by a patch).

The only things you need:
- configure DCMTK with -DDCMTK_CXX11_FLAGS:STRING=/Zc:__cplusplus
- add /Zc:__cplusplus to the CMAKE_CXX_FLAGS variable of your project

It would be nice if DCMTK could do the first automatically, or if it would not overwrite the flags with VS and C++11.

I wanted to provide a patch, but I'm not sure if this preview release can be distinguished from the previous previews reliably.

Maybe someone knows, how. Or anyway, maybe my findings will be useful for someone.

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: C++11 support with Visual Studio 15.7 Preview 3

#2 Post by Jan Schlamelcher »

What version of DCMTK are you using? We have some "per-feature" tests since DCMTK 3.6.2. I would be suprised if Visual Studio now implements std::error_code correctly, but this is also handled independently from the C++11 flag since version 3.6.2.

mespak
Posts: 9
Joined: Thu, 2018-02-15, 16:59

Re: C++11 support with Visual Studio 15.7 Preview 3

#3 Post by mespak »

3.6.3

It builds fine, although I did not run its tests. Compiler checks are done at configuration and build time, those do pass.

mespak
Posts: 9
Joined: Thu, 2018-02-15, 16:59

Re: C++11 support with Visual Studio 15.7 Preview 3

#4 Post by mespak »

I ran the tests.

In release mode all the tests pass.

On debug mode one test crashes because of an assertion failure inside the STL implementation of VS:

This test:

ofstd_OFVector

Screenshot of the error:

https://ibb.co/ijMWBc

At this line:
https://github.com/DCMTK/dcmtk/blob/DCM ... vec.cc#L51

It looks like a bug in the VS library.

mespak
Posts: 9
Joined: Thu, 2018-02-15, 16:59

Re: C++11 support with Visual Studio 15.7 Preview 3

#5 Post by mespak »

In debug mode this option has to be added to the C++ flags:

Code: Select all

/D_ITERATOR_DEBUG_LEVEL=1
The default value is 2 for debug builds, causing a crash.

Unfortunately, this cannot be added to CMAKE_CXX_FLAGS_DEBUG, because it gets overwritten when building static libs, but it can be added to DCMTK_CXX11_FLAGS. One must be careful not to set this for release builds, though.

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: C++11 support with Visual Studio 15.7 Preview 3

#6 Post by Jan Schlamelcher »

Interesting. It seems they really made progress. I have just added a feature to our issue tracker: https://support.dcmtk.org/redmine/issues/824

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest