DCMTK 3.6.2 (MD support library) and Microsoft Visual Studio 2017 development environment construction
- DCMTK 362MD support library and Microsoft Visual Studio 2017 development environment construction
Write in front
The recent classwork has come into contact with some developments about the medical image format Dicom. After nearly a semester of hard-working learning, finally, here are some problems encountered in the process.
In the learning process, most of the information found on the Internet is about the installation preparation of DCMTK 3.6.0, and most of them are out of date and the effective information is scattered, so this article first briefly records the development environment of DCMTK 3.6.2 Set up for future needs.
Knowledge preparation
DCMTK
DCMTK is an open source project provided by the German offis company . It is implemented in C++. After more than ten years of development and maintenance, it has basically realized all the contents of the Dicom protocol, and provided all source codes, support libraries and help documents. The best choice for this course project.
MT or MD?
The author Liu Beifeng'er mentioned in a blog post about DCMTK 3.6.0 compilation
MD/MT knowledge reserve:
/MT and /MTd indicate the static lib version of the multithreaded CRT library. This option will fully embed the runtime library as a static lib at compile time. The executable file generated by this option does not require the participation of the runtime library dll when it runs, and will obtain a slight performance improvement, but the resulting binary code becomes very bloated due to the huge runtime library implementation. When a project is embedded in multiple projects in the form of a static link library, it may cause multiple copies of the memory management of the runtime library, which will eventually lead to the fatal "Invalid Address specified to RtlValidateHeap" problem. In addition, the /MT and /MTd options are no longer supported in managed C++ and CLI.
/MD and /MDd indicate that the dynamic dll version of the multi-threaded CRT library is used, which will make the application use the specific version of the multi-threaded DLL of the runtime library. When linking, the import library MSVCRT.lib of the runtime library MSVCRxx.DLL will be linked according to the traditional VC link dll method. At runtime, the corresponding version of the VC runtime library redistributable component package will be installed (of course, these runtime libraries The dll can also be placed in the application directory).
Because the /MD and /MDd methods will not link the runtime library into the executable file, it can effectively reduce the size of the executable file. When multiple projects are operated in MD mode, the same heap will be used internally, memory management will be simplified, and cross-module memory management problems can also be alleviated.
Conclusion: /MD and /MDd will be the trend, /ML and /MLd methods please give up in time, and /MT and /MTd should not be used unless necessary.
Download software
DCMTK source code and corresponding version of MD support library
DCMTK3.6.2 source code and compiled executables can be completed on its official website direct download.
It should be noted that when downloading the MD support library, you must correctly select the corresponding operating system version and Visual Studio version. Here we choose to download:
dcmtk-3.6.2-win64-support_MD-msvc-15.0.zip
Pre-compiled libraries for Visual Studio 2017 (MSVC 15.0), 64 bit, with “MD” option
CMake
Cmake is required to generate the DCMTK source code. The choice of CMake version may not be so particular. This time I directly chose the latest stable version 3.10.0 that can be downloaded, but theoretically an updated version is also feasible.
I still have to say something, the source code of CMake is useless in this project. When downloading , please select Binary Distributions to download, and also select the version of the corresponding operating system to download.
Officially started
Use CMake to generate DCMTK project files
- Unzip the downloaded DCMTK source code package and support library package
- Open CMake to select the source code path and the code path to be generated
- Click Configure in the lower left corner, select the corresponding MS version in the pop-up dialog box, and then Finish to confirm
- It may take a long time to finish the order. The first time you have to check many things, the list should be so red after running.
- The yellow box in the figure above is where the support library we just downloaded is to be set up. CMake does not automatically recognize the path, we need to set it manually.
The directory structure of the downloaded support library is as follows: - After setting all these support library paths, it should be as shown in the following figure (each person supports the inventory placement path is different, the path in the figure is for reference only, the actual one shall prevail):
- In the configuration, check all the items with the configured path, and uncheck DCMTK_OVERWRITE_WIN32_COMPILER_FLAGS (very critical) .
- At this point, click Configure again. After a short reading, the list should all become white. Check whether the changes you have made before are still retained. If the path and checkboxes are still retained, the settings have been successful. Click Generate to generate the project file. .
- At this point, the work on CMake is all over, and CMake can be closed for subsequent operations.
Open the obtained DCMTK project file for batch generation
- (Very important) Because the wrong file name is quoted in the project configuration file generated by CMake, the generated project file must be modified: open the DCMTK project directory, open and modify the
./dcmnet/apps/cmake_install.cmake
file, and search the full textopenssl
. You will find that this paragraph refers to two non-existent file namesdcmtkeay.dll
anddcmtkssl.dll
, respectively, modify them to the previously downloaded support library./openssl-1.1.0f/bin/dcmtkcrypto_d-1_1-x64.dll
and./openssl-1.1.0f/bin/dcmtkssl_d-1_1-x64.dll
you can (Release version select the file without _d suffix to modify), save and close after modification. - Use the administrator authority to open the obtained DCMTK project solution (DCMTK.sln) with Visual Studio
- From the menu bar, select Generate (B) -> Batch Generation (T)...
- In the pop-up dialog box, check the ALL_BUILD project of the Debug configuration (to generate the Release version file, select the Release configuration here and in the subsequent steps), and click Generate.
Facts have proved that this step will take a very long time (picture transfer network invasion and deletion) - When you get a prompt similar to the following, it means that this step has been completed
- Repeat step 3, but check one more INSTALL project under Debug configuration (select Release in Release environment), and then click Generate.
- If there is no error, congratulations, DCMTK 3.6.2 has been compiled successfully,
Write sample programs for testing
Project settings
Create a new VC++ empty project, set the project solution configuration to debug, the solution platform is x64, and add the source file main.cpp.
Enter the menu bar project (P) -> YOUR_PROJECT_NAME_ property (note that the modification is the x64 configuration under debug, if you change to release, you must reset it to the configuration under the release scheme).
C/C++–>General on the left, and an additional include directory on the right, set to C:\Program Files\DCMTK\include
(default location).
Linker on the left -> General, additional library directory on the right, set to C:\Program Files\DCMTK\lib
你下载并解压的支持库目录\zlib-1.2.11\lib
Linker on the left -> input, additional dependencies on the right, set to Iphlpapi.lib
ws2_32.lib
wsock32.lib
netapi32.lib
ofstd.lib
oflog.lib
dcmdata.lib
dcmdsig.lib
dcmnet.lib
dcmsr.lib
dcmimgle.lib
dcmqrdb.lib
dcmtls.lib
dcmwlm.lib
dcmpstat.lib
dcmjpls.lib
dcmjpeg.lib
dcmimage.lib
charls.lib
ijg8.lib
ijg12.lib
ijg16.lib
i2d.lib
zlib_d.lib(Release版本删除_d)
Attach a lib dependency graph, you don’t need to add all of them when you encounter specific problems later, just select what you need and its dependencies
Sample code
//filename: main.cpp
#include "dcmtk\config\osconfig.h"
#include "dcmtk\dcmdata\dctk.h"
#include <iostream>
void main() {
DcmFileFormat *myFileFormat = new DcmFileFormat;
OFCondition cond = myFileFormat->loadFile("c:/111.dcm");
if (cond.good()){
OFString patientName;
if (myFileFormat->getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
std::cout << "Patient Name: " << patientName << "\nTest successed.\n";
else std::cout << "No Patient Name Data!\n";
}
else std::cout << "Error occurs when opening file, check path or filename.\n";
system("pause");
}
Finally, attach the dicom format picture used in the test. Extract password: cw3q
If the Patient Name parameter can be displayed correctly, congratulations, the DCMTK library has been installed correctly, and you can proceed to the next development work!