FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC]

Frequently Asked Questions regarding DCMTK

Moderator: FAQ Team

Post Reply
Message
Author
Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC]

#1 Post by Jörg Riesmeier »

:?: How do I use the DCMTK 3.5.4 libraries in my own application?

:!: Here's an example for the Windows platform (MSVC):
  1. Create DCMTK project files with CMake (for demonstration purposes switch all external libraries off).
  2. Open the main project file "dcmtk.dsw" or "dcmtk.sln" in Visual Studio.
  3. Select target ALL_BUILD and compile the complete DCMTK.
  4. Select target INSTALL in order to install the DCMTK files to the directory specified using CMake.
  5. Create a new directory "testapp" somewhere on your harddisk with the following files.
Example program "testapp.cxx" from the dcmdata documentation:

Code: Select all

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"

int main()
{
  DcmFileFormat fileformat;
  OFCondition status = fileformat.loadFile("test.dcm");
  if (status.good())
  {
    OFString patientsName;
    if (fileformat.getDataset()->findAndGetOFString(DCM_PatientsName, patientsName).good())
    {
      cout << "Patient's Name: " << patientsName << endl;
    } else
      cerr << "Error: cannot access Patient's Name!" << endl;
  } else
    cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
  return 0;
}
Add minimum CMakeLists.txt file for MSVC6 and adjust path to installed DCMTK (if required):

Code: Select all

PROJECT(testapp)

SET(DCMTK_DIR /dicom/dcmtk-3.5.4-win32-i386)

# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")

ADD_DEFINITIONS(-D_REENTRANT)

INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)

ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)
Finally, create the project files for the test application using CMake and compile it using MSVC.

J. Riesmeier
DCMTK Developer
Posts: 2542
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC]

#2 Post by J. Riesmeier »

To readers of this FAQ entry:

The above described approach refers to a rather old DCMTK version. For more recent versions of this toolkit, CMake's find_package() mechanism should be used. Compiler flags should no longer be set directly.

Please also note that the name of some tag constants changed back in 2009 when the data dictionary was switched to the official keywords from DICOM part 6 for the attribute names. Therefore, for newer DCMTK versions, the tag constant DCM_PatientName should be used instead of DCM_PatientsName (i.e. the "s" has been removed).

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest