External libs with mingw

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
gzhang
Posts: 50
Joined: Wed, 2015-09-02, 09:24

External libs with mingw

#1 Post by gzhang »

Hi,

I am using a MinGW compiler suite on Windows with prepared external libs (OpenSSL, zlib, libtiff, libpng and libxml2) in place. However, CMake wasn't able to pick them up even if they are on the system search paths (CPATH, LIBRARY_PATH, etc). Even more, if I chose to specify the paths explicitly with "WITH_LIBXMLINC", "WITH_LIBPNGINC", etc, CMake still cannot find correct files because I think it was trying to look for "*.lib" instead of "*.a". Is there a way to get around this? Thanks!

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

Re: External libs with mingw

#2 Post by Jan Schlamelcher »

Sorry, I wanted to have commited this some time ago, but I did not come to do serious testing with it:

Code: Select all

diff --git a/CMake/3rdparty.cmake b/CMake/3rdparty.cmake
index 9fcca77..b40f88b 100755
--- 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)
This patch effectively changes the used find_package mechanism so that MinGW is handled the same as UNIX, which always worked for me.

gzhang
Posts: 50
Joined: Wed, 2015-09-02, 09:24

Re: External libs with mingw

#3 Post by gzhang »

I finally had time to try this again :-)

1) I first updated the "3rdparty.make" file:
IF(WIN32) to IF(WIN32 AND NOT MINGW)
ELSE(WIN32) to ELSE(WIN32 AND NOT MINGW)
2) Prepared libtiff etc, and then configure dcmtk with CMake/MinGW
3) in CMake, turned on "DCMTK_WITH_TIFF" etc;
4) in CMake, set "WITH_LIBTIFFINC" etc to my $(PATH_INSTALL), which contains lib/libtiff.a etc and include/tiff.h etc

However, CMake still reported that libtiff couldn't be located. Same occurred for libpng, libiconv, etc
May you have any idea where I might get wrong? You said it would be treated exactly as in Unix. Does it also apply to mingw in windows? Or msys or something? Thanks

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

Re: External libs with mingw

#4 Post by Jan Schlamelcher »

You're setting the wrong variables (the Windows ones). The patch makes CMake recognize the UNIX style variables, see here for an example regarding libtiff.

gzhang
Posts: 50
Joined: Wed, 2015-09-02, 09:24

Re: External libs with mingw

#5 Post by gzhang »

Well, still fail to work with the following
TIFF_INCLUDE_DIR=$(PATH_INSTALL)/include
TIFF_LIBRARY=$(PATH_INSTALL)/lib
TIFF_LIBRARIES=libtiff.a (I have also tried "tiff", "$(TIFF_LIBRARY)/libtiff.a")
Just about to retry with cmake on command line. Might there be any difference with the gui...

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

Re: External libs with mingw

#6 Post by Jan Schlamelcher »

As far as I know, you'll have to set TIFF_LIBRARY to $(PATH_INSTALL)/lib/libtiff.a.
Also, just to be sure, you still need to enable DCMTK_WITH_TIFF.

This is what my FindTIFF.cmake does:

Code: Select all

  set(TIFF_LIBRARIES ${TIFF_LIBRARY})
  set(TIFF_INCLUDE_DIRS "${TIFF_INCLUDE_DIR}")

  if(NOT TARGET TIFF::TIFF)
    add_library(TIFF::TIFF UNKNOWN IMPORTED)
    if(TIFF_INCLUDE_DIRS)
      set_target_properties(TIFF::TIFF PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}")
    endif()
    if(EXISTS "${TIFF_LIBRARY}")
      set_target_properties(TIFF::TIFF PROPERTIES
        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
        IMPORTED_LOCATION "${TIFF_LIBRARY}")
    endif()

gzhang
Posts: 50
Joined: Wed, 2015-09-02, 09:24

Re: External libs with mingw

#7 Post by gzhang »

Hi Jan,
thanks for the instructions! I have defined the variables exactly the same way as they are used in 3rdparty.make, but there's still some problem, which is quite strange to me. The reason I am linking external libs is mainly for libiconv, which I guess would allow me to call e.g. DcmFileFormat.loadFile() using file names/paths containing Unicode characters. Since cmake is somehow stuck at this step, probable writing a wrapper function with libiconv and then use the wrapper to convert the characters before I make the call would be easier... keep trying...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest