网上关于mingw编译dcmtk的文章太少,不方便查阅,期间遇到各种问题。特意将整个编译过程记录下来。为了保证所有编译出来的文件方便我在Qt5.5.0中使用,将所有的dcmtk依赖的外部库下载下来并进行编译。整个编译过程如下。注,除msys外,其余所有依赖库,均在此处下载:http://www.dcmtk.org/dcmtk.php.en,所有安装包,依赖库,均解压到d盘下;
版本:1.2.5
新建文件夹libzlib,并将zlib解压后放置在libzlib文件夹中,同时,再在内部新建文件夹out,方便讲编译出来的文件提取安装到out中。(即源码路径为:d:/libzlib/zlib-1.2.5。输入文件路径为d:/libzlib/out)
在zlib文件夹中打开命令行,输入:
copy win32\makefile.gcc makefile.gcc
mingw32-make -f makefile.gcc
目前为止,暂未编译通过,每次生成dll都会失败,但因为不需要dll,只需要动态库,故暂时未管。将zonf.h提取到out中的include文件夹中,将libz.a放到out中的lib文件夹中。
编译后的下载链接:http://download.csdn.net/detail/syz9011/9261495
版本:1.4.3
新建文件夹libpng,并将libpng-1.4.3解压后放置在libpng文件夹中,同时,再在内部新建文件夹out,方便讲编译出来的文件提取安装到out中.(即源码路径为:d:/libpng/libpng-1.4.3。输入文件路径为d:/libpng/out)
打开scripts/makefile.gcc设置zlib路径:
ZLIBINC = d:/libzlib/out
ZLIBLIB = d:/libzlib/out
运行msys.bat,并cd到libpng-1.4.3路径中,输入如下:
./configure --prefix=d:/libpng/out
make
make install
编译后的下载链接:http://download.csdn.net/detail/syz9011/9261475
因编译LIBTIFF需要依赖于LIBJPG,故需要编译此库
下载地址:http://www.ijg.org/files/jpegsr9a.zip
路径放置同上:
即源码路径为:d:/libjpeg/jpeg-9a。输入文件路径为d:/libjpeg/out
运行msys.bat,并cd到jpeg-9a路径中,输入如下:
./configure --prefix=d:/libpng/out
打开jconfig.h,增加以下定义:
#define HAVE_PROTOTYPES 1
保存,然后继续在msys.bat中输入如下:
make
make install
编译后的下载链接:http://download.csdn.net/detail/syz9011/9247035
路径放置同上:
即源码路径为:d:/libtiff/tiff-3.9.4。输入文件路径为d:/libtiff/out
运行msys.bat,并cd到tiff-3.9.4路径中,输入如下:
./configure --with-zlib-include-dir=d:/libzlib/out --with-zlib-lib-dir=d:/libzlib/out --with-jpeg-include-dir=d:/libjpeg/out/include --with-jpeg-lib-dir=d:/libjpeg/out/lib --prefix=d:/libtiff/out
make
make install
注意,编译完成后,需要将libjpeg中的libjpeg.dll.a拷贝到libtiff的out的lib文件夹下,否则dcmtk编译会出错。
编译后的下载链接:http://download.csdn.net/detail/syz9011/9261485
路径放置同上:
即源码路径为:d:/libiconv/libiconv-1.13.1。输入文件路径为d:/libiconv/out
运行msys.bat,并cd到libiconv-1.13.1路径中,输入如下:
./configure --prefix=d:/libiconv/out
make
make install
编译后的下载链接:http://download.csdn.net/detail/syz9011/9247017
路径放置同上:
即源码路径为:d:/libopenssl/openssl-1.0.0c。输入文件路径为d:/libopenssl/out
此时,进入到d:/libopenssl/openssl-1.0.0c/test文件夹下,打开md2test.c,将内容从 dummytest.c 改为 #include “dummytest.c”,同样的还有rc5test.c以及jpaketest.c
运行msys.bat,并cd到openssl-1.0.0c路径中,输入如下:
./config shared --prefix=d:/libopenssl/out
make depend
make
make test
make install
编译后的下载链接:http://download.csdn.net/detail/syz9011/9261499
路径放置同上:
即源码路径为:d:/libxml/libxml2-2.7.7。输入文件路径为d:/libxml/out
运行msys.bat,并cd到libxml2-2.7.7路径中,输入如下:
./configure --prefix=d:/libxml/out
make
make install
注意,编译完成之后,需要到out路径下,打开include文件夹,并将libxml2文件夹内的libxml文件夹拷贝到include文件夹下面,否则之后编译DCMTK时,会出现找不到libxml头文件的情况。另外,将libiconv中编译出来的.dll.a文件拷贝到libxml中的out中的lib文件夹下
ps:mingw4.8版本make过程中会报错,undefined reference _imp__xmlfree。mingw4.9.2不会
编译后的下载链接:http://download.csdn.net/detail/syz9011/9261491
路径放置同上:
即源码路径为:d:/dcmtk/dcmtk-3.6.1_20150924。输入文件路径为d:/dcmtk/out。编译输出路径为d:/dcmtk/gcc.
打开源码路径下CMake文件夹下的3rdparty.cmake,并做如下更改:
# libxml support: configure compiler
IF(DCMTK_WITH_XML)
IF(WITH_LIBXMLINC)
SET(LIBXML_INCDIR ${WITH_LIBXMLINC}/include)
SET(LIBXML_LIBDIR ${WITH_LIBXMLINC}/lib)
IF(MINGW)
SET(LIBXML_LIBS debug ${LIBXML_LIBDIR}/libxml2.a optimized ${LIBXML_LIBDIR}/libxml2.a debug ${LIBXML_LIBDIR}/libiconv.dll.a optimized ${LIBXML_LIBDIR}/libiconv.dll.a debug ${LIBXML_LIBDIR}/libxml2.dll.a optimized ${LIBXML_LIBDIR}/libxml2.dll.a debug ${LIBXML_LIBDIR}/libcharset.a optimized ${LIBXML_LIBDIR}/libcharset.a)
ELSE(MINGW)
SET(LIBXML_LIBS debug ${LIBXML_LIBDIR}/libxml2_d.lib optimized ${LIBXML_LIBDIR}/libxml2_o.lib debug ${LIBXML_LIBDIR}/iconv_d.lib optimized ${LIBXML_LIBDIR}/iconv_o.lib)
MESSAGE(STATUS "Info: DCMTK XML support will be enabled")
ENDIF(MINGW)
SET(WITH_LIBXML 1)
ELSE(WITH_LIBXMLINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: XML support will be disabled because libxml2 directory is not specified. Correct path and re-enable DCMTK_WITH_XML.")
SET(DCMTK_WITH_XML OFF CACHE BOOL "" FORCE)
SET(WITH_LIBXML "")
ENDIF(WITH_LIBXMLINC)
ENDIF(DCMTK_WITH_XML)
# libpng support: configure compiler
IF(DCMTK_WITH_PNG)
IF(WITH_LIBPNGINC)
SET(LIBPNG_INCDIR ${WITH_LIBPNGINC}/include)
SET(LIBPNG_LIBDIR ${WITH_LIBPNGINC}/lib)
IF(MINGW)
SET(LIBPNG_LIBS debug ${LIBPNG_LIBDIR}/libpng.a optimized ${LIBPNG_LIBDIR}/libpng.a)
ELSE(MINGW)
SET(LIBPNG_LIBS debug ${LIBPNG_LIBDIR}/libpng_d.lib optimized ${LIBPNG_LIBDIR}/libpng_o.lib)
ENDIF(MINGW)
MESSAGE(STATUS "Info: DCMTK PNG support will be enabled")
SET(WITH_LIBPNG 1)
ELSE(WITH_LIBPNGINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: PNG support will be disabled because libpng directory was not specified. Correct path and re-enable DCMTK_WITH_PNG.")
SET(DCMTK_WITH_PNG OFF CACHE BOOL "" FORCE)
SET(WITH_LIBPNG "")
ENDIF(WITH_LIBPNGINC)
ENDIF(DCMTK_WITH_PNG)
# libtiff support: configure compiler
IF(DCMTK_WITH_TIFF)
IF(WITH_LIBTIFFINC)
SET(LIBTIFF_INCDIR ${WITH_LIBTIFFINC}/include)
SET(LIBTIFF_LIBDIR ${WITH_LIBTIFFINC}/lib)
IF(MINGW)
SET(LIBTIFF_LIBS debug ${LIBTIFF_LIBDIR}/libtiff.a optimized ${LIBTIFF_LIBDIR}/libtiff.a debug ${LIBTIFF_LIBDIR}/libjpeg.a optimized ${LIBTIFF_LIBDIR}/libjpeg.a debug ${LIBTIFF_LIBDIR}/libjpeg.dll.a optimized ${LIBTIFF_LIBDIR}/libjpeg.dll.a)
ELSE(MINGW)
SET(LIBTIFF_LIBS debug ${LIBTIFF_LIBDIR}/libtiff_d.lib optimized ${LIBTIFF_LIBDIR}/libtiff_o.lib)
ENDIF(MINGW)
MESSAGE(STATUS "Info: DCMTK TIFF support will be enabled")
SET(WITH_LIBTIFF 1)
ELSE(WITH_LIBTIFFINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: TIFF support will be disabled because libtiff directory was not specified. Correct path and re-enable DCMTK_WITH_TIFF.")
SET(DCMTK_WITH_TIFF OFF CACHE BOOL "" FORCE)
SET(WITH_LIBTIFF "")
ENDIF(WITH_LIBTIFFINC)
ENDIF(DCMTK_WITH_TIFF)
# OpenSSL support: configure compiler
IF(DCMTK_WITH_OPENSSL)
IF(WITH_OPENSSLINC)
SET(OPENSSL_BINDIR ${WITH_OPENSSLINC}/bin)
SET(OPENSSL_INCDIR ${WITH_OPENSSLINC}/include)
SET(OPENSSL_LIBDIR ${WITH_OPENSSLINC}/lib)
IF(MINGW)
SET(OPENSSL_LIBS debug ${OPENSSL_LIBDIR}/libcrypto.dll.a optimized ${OPENSSL_LIBDIR}/libcrypto.dll.a debug ${OPENSSL_LIBDIR}/libssl.dll.a optimized ${OPENSSL_LIBDIR}/libssl.dll.a)
ELSE(MINGW)
SET(OPENSSL_LIBS debug ${OPENSSL_LIBDIR}/dcmtkssl_d.lib optimized ${OPENSSL_LIBDIR}/dcmtkssl_o.lib debug ${OPENSSL_LIBDIR}/dcmtkeay_d.lib optimized ${OPENSSL_LIBDIR}/dcmtkeay_o.lib)
ENDIF(MINGW)
MESSAGE(STATUS "Info: DCMTK OPENSSL support will be enabled")
SET(WITH_OPENSSL 1)
ELSE(WITH_OPENSSLINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: OPENSSL support will be disabled because openssl directory was not specified. Correct path and re-enable DCMTK_WITH_OPENSSL.")
SET(DCMTK_WITH_OPENSSL OFF CACHE BOOL "" FORCE)
SET(WITH_OPENSSL "")
ENDIF(WITH_OPENSSLINC)
ENDIF(DCMTK_WITH_OPENSSL)
# zlib support: configure compiler
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}/zlib.a optimized ${ZLIB_LIBDIR}/zlib.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)
# sndfile support: configure compiler
IF(DCMTK_WITH_SNDFILE)
IF(WITH_SNDFILEINC)
SET(SNDFILE_INCDIR ${WITH_SNDFILEINC}/include)
SET(SNDFILE_LIBDIR ${WITH_SNDFILEINC}/lib)
IF(MINGW)
SET(SNDFILE_LIBS debug ${SNDFILE_LIBDIR}/libsndfile.a optimized ${SNDFILE_LIBDIR}/libsndfile.a)
ELSE(MINGW)
SET(SNDFILE_LIBS debug ${SNDFILE_LIBDIR}/libsndfile_d.lib optimized ${SNDFILE_LIBDIR}/libsndfile_o.lib)
ENDIF(MINGW)
MESSAGE(STATUS "Info: DCMTK SNDFILE support will be enabled")
SET(WITH_SNDFILE 1)
ELSE(WITH_SNDFILEINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: SNDFILE support will be disabled because libsndfile directory was not specified. Correct path and re-enable DCMTK_WITH_SNDFILE.")
SET(DCMTK_WITH_SNDFILE OFF CACHE BOOL "" FORCE)
SET(WITH_SNDFILE "")
ENDIF(WITH_SNDFILEINC)
ENDIF(DCMTK_WITH_SNDFILE)
# libiconv support: configure compiler
IF(DCMTK_WITH_ICONV)
IF(WITH_LIBICONVINC)
SET(LIBICONV_INCDIR ${WITH_LIBICONVINC}/include)
SET(LIBICONV_LIBDIR ${WITH_LIBICONVINC}/lib)
IF(MINGW)
SET(LIBICONV_LIBS debug ${LIBICONV_LIBDIR}/libiconv.dll.a optimized ${LIBICONV_LIBDIR}/libiconv.dll.a debug ${LIBICONV_LIBDIR}/libcharset.a optimized ${LIBICONV_LIBDIR}/libcharset.dll.a)
ELSE(MINGW)
SET(LIBICONV_LIBS debug ${LIBICONV_LIBDIR}/libiconv.dll.a optimized ${LIBICONV_LIBDIR}/libiconv_o.lib)
ENDIF(MINGW)
MESSAGE(STATUS "Info: DCMTK ICONV support will be enabled")
SET(WITH_LIBICONV 1)
ELSE(WITH_LIBICONVINC) # turn off library if library path not set
MESSAGE(STATUS "Warning: ICONV support will be disabled because libiconv directory was not specified. Correct path and re-enable DCMTK_WITH_ICONV.")
SET(DCMTK_WITH_ICONV OFF CACHE BOOL "" FORCE)
SET(WITH_LIBICONV "")
ENDIF(WITH_LIBICONVINC)
ENDIF(DCMTK_WITH_ICONV)
ELSE(WIN32)
打开CMake工具,并设置好源代码路径以及编译临时路径。点击Configure,出现红色界面,将所有路径配置好之后,点击Generate。界面截图如下:(注意,因我的电脑只有C盘,所有,我所有的路径都在c:/vs下)
运行msys.bat,并cd到gcc路径中,输入如下:
make
make install
csdn下载资源:
编译之后的包:http://download.csdn.net/detail/syz9011/9246233
参考资料:
http://www.gaia-gis.it/gaia-sins/mingw_how_to.html