Problem compiling dcmtk-3.6.5 with openSSL 1.1.1i

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Markus Sabin
Posts: 93
Joined: Tue, 2005-07-12, 13:50
Location: Erlangen, Germany

Problem compiling dcmtk-3.6.5 with openSSL 1.1.1i

#1 Post by Markus Sabin » Mon, 2021-01-25, 11:07

Dear DCMTK experts,

I am desperatly struggling to compile the latest dcmtk release with the latest release of openSSL for Windows.

I have obtained the source code for openSSL 1.1.1i and compiled/installed it successfully (which was a struggle of its own, since the latest version of the recommended ActiveState perl did not work very well - everyone who reads this: Use Strawberry!).

Then I set the options in the CMAKE for dcmtk using cmake-gui:
- DCMTK_WITH_OPENSSL -> check
- WITH_OPENSSLINC -> <path to the root of my installed openSSL version>

I am quite sure though not absolutely sure that I have set the path correctly - more on this later.

When I am configuring the CMAKE-process, the following error occurs:

Code: Select all

Info: DCMTK OPENSSL support will be disabled: DCMTK requires OpenSSL version 1.0.1 or newer
I suspect this is the root cause of my problems, but I cannot find a clue.

What I have tried to solve it:
I found that the error message comes from a version check in 3rdparty.cmake, line 98:

Code: Select all

CHECK_CXX_SOURCE_COMPILES("extern \"C\" {\n#include <openssl/ssl.h>\n}\nint main(){\n#if OPENSSL_VERSION_NUMBER < 0x10001000L\n#error OpenSSL too old\n#endif\n}\n" OPENSSL_VERSION_CHECK)
I verified the version number in opensslv.h:

Code: Select all

# define OPENSSL_VERSION_NUMBER  0x1010109fL
Seems OK, and I have programatically verified that (0x1010109fL > 0x10001000L) yields "true"

So I wanted to force CMAKE to build with openSSL and changed line 98 in 3rdparty.cmake like this:

Code: Select all

set(OPENSSL_VERSION_CHECK 1)
Obviously, this makes the error message disappear and generates makefiles for VC with SSL support. I am loading the generated solution into Visual Studio, and DCMTK tries to compile with openSSL support. It does find the header files of openSSL, which is why I strongly believe that I have set the correct path for WITH_OPENSSLINC. But otherwise, it behaves more than strange. The compilation raises errors. The very most of these errors are referring to code blocks which are surrounded by

Code: Select all

#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
(or similar).

Strangely, the VS editor shows these blocks "grayed out", i.e. it seems to obtain the correct version number from opensslv.h, Code navigation follows the symbol OPENSSL_VERSION_NUMBER to the correct header file in v1.1.1i. But the compiler seems to have different preprocessor symbols. Other errors refer to openssl functionality which is not surrounded by #ifdefs, e.g. X509_LOOKUP_add_dir is undefined (though code navigation also finds this in x509_vfy.h).

It is certainly not the best idea to bypass the version check in CMAKE, but to me the subsequent observations are noteworthy and tell me that I have appropriately set the path to the openSSL library, that the version is newer and should pass the check in CHECK_CXX_SOURCE_COMPILES, and that the generated makefiles for VC are pointing to the correct version of openssl.

Any hints will be much appreciated.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1280
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Problem compiling dcmtk-3.6.5 with openSSL 1.1.1i

#2 Post by Marco Eichelberg » Fri, 2021-01-29, 09:01

Hi Markus,

I would guess that there is another installation of OpenSSL somewhere in your search path. WITH_OPENSSLINC ensures that the path where your new OpenSSL installation is located will be included into the search paths for header files and libraries, but if another version is found earlier than that in the path, this would explain the problem.

Perhaps you can check the output of the preprocessor (cl.exe /P:<filename>), where the path to the actual OpenSSL header file included should be annotated with a #line comment.

Markus Sabin
Posts: 93
Joined: Tue, 2005-07-12, 13:50
Location: Erlangen, Germany

Re: Problem compiling dcmtk-3.6.5 with openSSL 1.1.1i

#3 Post by Markus Sabin » Tue, 2021-02-02, 11:14

For those who may find this helpful: My problem is now solved.

Mainly, it was a stupid mistake resulting from not being much used to work with MS Visual Studio.

The reason why CMake did not recognize the openssl version was apparently related to a previously built osconfig.h residing in the target directory of the build. I did not investigate this further (I thought osconfig.h was generated by the CMake process) but I could solve this by building in clean paths.

In fact, there were only two compiler errors, but the error list in MSVS showed a big bunch of them - many of them in blocks that appeared grayed out. The vast majority of them was related to IntelliSense however, I did not notice that they were not compilation issues. The remaining issues:

Code: Select all

 
 error C2027: use of undefined type 'ssl_ctx_st'
 error C2789: 'parameter': an object of const-qualified type must be initialized
 
could be solved by adding

Code: Select all

/DHAVE_SSL_CTX_GET0_PARAM
to the CMAKE_CXX_FLAGS, then compilation succeeded.

For successful linking, I had to create copies of the libssl and libcrypto as described here: https://forum.dcmtk.org/viewtopic.php?t=4744

Now everything works fine. Thanks to the OFFIS team for the great support!

[EDIT:] The Linux build was super-smooth - took less than 1/2 hour, including the build of openssl-1.1.1i from the sources

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest