Skip to content
Advertisement

How to link properly Dcmtk with Qt for Linux?

My goal is open Dicom files and convert thes into cv::Mat to process them with Opencv.

I have compiled dcmtk 3.6.3 on ubuntu 18.4.1 and tried to link it with Qt 5.11.1 with Qt Creator 4.6.2 but failed to do so.

# pro file
QT       += core
QT       -= gui

TARGET = DcmtkTesting
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


DCMTK_PREFIX = "/home/ismail/dcmtk363"
DCMTK_LIBS_PREFIX=$$DCMTK_PREFIX"/lib"
DCMTK_INCLUDE=$$DCMTK_PREFIX"/include"
INCLUDEPATH+=$$DCMTK_INCLUDE

LIBS += -L$$DCMTK_LIBS_PREFIX

SOURCES += main.cpp

and for the main: #include

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include <dcmtk/dcmimgle/dcmimage.h>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    DicomImage *image = new DicomImage("test.dcm");
    if (image != NULL)
    {
      if (image->getStatus() == EIS_Normal)
      {
        if (image->isMonochrome())
        {
          image->setMinMaxWindow();
          Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits*/));
          if (pixelData != NULL)
          {
            /* do something useful with the pixel data */
          }
        }
      } else
        cout << "Error: cannot load DICOM image (" <<   DicomImage::getString(image->getStatus()) << ")" << endl;
    }
    delete image;

    return a.exec();
}

and I got this errors:

enter image description here

Advertisement

Answer

The error indicates that the linker could not find the symbols (methods) provided by the library. In your .pro file, you pointed the linker to a directory where your library is located, but you forgot to specify which library should be linked.

So you have to modify the line LIBS +=... accordingly, e.g.:

LIBS += -L$$DCMTK_LIBS_PREFIX -ldcmtk

Since I don’t know the actual name of the library, I use dcmtk in my example. You may have to adopt it to fit your build environment. Just make sure that you have the -l (lower case L), immediately followed by the library name.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement