Error in "3rdparty.cmake" on MinGW or MinGW64

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
ScreamingInDigital
Posts: 2
Joined: Mon, 2015-03-02, 10:53

Error in "3rdparty.cmake" on MinGW or MinGW64

#1 Post by ScreamingInDigital »

The file "3rdparty.cmake" assumes that all libraries have the extension ".lib", which is the default for Microsoft Visual C++. However, MinGW and MinGW64 use archiver which will create a library in the format "lib<name>.a" like all other *nix platforms.

Each section should be modified to check for MinGW. Here is a change I made to correctly find zlib. This is a very simple change for each section that will allow the external libraries to be used.
==========
IF(DCMTK_WITH_ZLIB)
IF(WITH_ZLIBINC)
SET(ZLIB_INCDIR ${WITH_ZLIBINC}/include)
SET(ZLIB_LIBDIR ${WITH_ZLIBINC}/lib)
IF(MINGW)
SET(ZLIB_LIBS debug ${ZLIB_LIBDIR}/libz_d.a optimized ${ZLIB_LIBDIR}/libz.a)
ELSE(MINGW)
SET(ZLIB_LIBS debug ${ZLIB_LIBDIR}/zlib_d.lib optimized ${ZLIB_LIBDIR}/zlib_o.lib)
ENDIF(MINGW)
MESSAGE(STATUS "Info: DCMTK ZLIB support will be enabled")
SET(WITH_ZLIB 1)
ELSE(WITH_ZLIBINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: ZLIB support will be disabled because zlib directory was not specified. Correct path and re-enable DCMTK_WITH_ZLIB.")
SET(DCMTK_WITH_ZLIB OFF CACHE BOOL "" FORCE)
SET(WITH_ZLIB "")
ENDIF(WITH_ZLIBINC)
ENDIF(DCMTK_WITH_ZLIB)
===========

Some IDEs, such as Eclipse, look for "MINGW_HOME", so it might be useful to add
...
SET(ZLIB_LIBS debug ${ZLIB_LIBDIR}/libz_d.a optimized ${ZLIB_LIBDIR}/libz.a)
IF(IS_DIRECTORY $ENV{MINGW_HOME}/x86_64-w64-mingw32/include)
SET(ZLIB_INCDIR $ENV{MINGW_HOME}/x86_64-w64-mingw32/include)
SET(ZLIB_LIBDIR $ENV{MINGW_HOME}/x86_64-w64-mingw32/lib)
ELSEIF(IS_DIRECTORY $ENV{MINGW_HOME}/mingw/include)
SET(ZLIB_INCDIR $ENV{MINGW_HOME}/mingw/include)
SET(ZLIB_LIBDIR $ENV{MINGW_HOME}/mingw/lib)
ELSEIF(IS_DIRECTORY $ENV{MINGW_HOME}/include)
SET(ZLIB_INCDIR $ENV{MINGW_HOME}/include)
SET(ZLIB_LIBDIR $ENV{MINGW_HOME}/lib)
ENDIF(IS_DIRECTORY $ENV{MINGW_HOME}/x86_64-w64-mingw32/include)
...
This would automatically set the correct include and lib folders to search for the libraries.
Again, this could be done for the other libraries such as libtiff, libpng, etc..
MinGW64 uses both %MINGW_HOME%/x86_64-w64-mingw32/include and %MINGW_HOME%/mingw/include for include, and the same for the "lib" folders. I do not know why it has both. These will not exist for the standard 32-bit MinGW.

I have not tried to build with msys and your configure script, but it is not necessary.

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

Re: Error in "3rdparty.cmake" on MinGW or MinGW64

#2 Post by Jan Schlamelcher »

Yes, that is a known issue. I personally always changed "3rdparty.cmake" as follows:

Code: Select all

diff --git a/CMake/3rdparty.cmake b/CMake/3rdparty.cmake
old mode 100755
new mode 100644
index 9fcca77..b40f88b
--- a/CMake/3rdparty.cmake
+++ b/CMake/3rdparty.cmake
@@ -1,4 +1,4 @@
-IF(WIN32)
+IF(WIN32 AND NOT MINGW)
 
   # For Windows, we don't used FIND_PACKAGE because DCMTK usually is used with its
   # own set of 3rd-party support libraries that can be downloaded from DCMTK's
@@ -139,7 +139,7 @@ IF(WIN32)
     ENDIF(WITH_LIBICONVINC)
   ENDIF(DCMTK_WITH_ICONV)
 
-ELSE(WIN32)
+ELSE(WIN32 AND NOT MINGW)
 
   # Find TIFF
   IF(DCMTK_WITH_TIFF)
Which simply uses the same find functions like under Unix and seems to work for MinGW. But I did not find the time to do further testing so far, thats why it's not in the DCMTK yet.

ScreamingInDigital
Posts: 2
Joined: Mon, 2015-03-02, 10:53

Re: Error in "3rdparty.cmake" on MinGW or MinGW64

#3 Post by ScreamingInDigital »

Okay. I definitely understand that it would not be a priority considering Visual Studio is now free. I am sure there are purists that would rather stick to using gcc, and possibly prefer CMake over autotools. However, this is probably a small group! :shock: I did get it to work fine with zlib. I will make some of the changes and try to build with the other libraries.

I would also suggest adding to the "INSTALL" file to strongly recommend using Ultimate Packer for Executables if building on MinGW64 as "Release" or "Minimum Size Release". The 64-bit build will obviously result in larger binaries than a 32-bit build, but MinGW64's binaries are very large. It is probably overkill to build native 64-bit on Windows.

And, of course, you may want to recommend to be patient building with MinGW. :x The compiler and linker are very slow compared to MSVC.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest