I am trying to load a monochrome dicom image file using DCMTK with the example code provided in the docs
http://support.dcmtk.org/docs/mod_dcmimgle.html
The file I am trying to compile is dcmtest.cxx which contains the following code:
#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmimgle/dipixel.h"
#include "dcmtk/dcmimgle/diimage.h"
#include "dcmtk/dcmimgle/dimo1img.h"
#include "dcmtk/dcmimgle/dimo2img.h"
#include <iostream>
using namespace std;
int main()
{
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
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;
}
I am trying to compile code with:
g++ dcmtest.cxx -DHAVE_CONFIG_H -I$HOME/dcmtk361_std/include -L$HOME/dcmtk361_std/lib -pthread -ldcmdata -lz -loflog -lofstd -o main
which I got from
However, I am getting the error
/tmp/cchsrh2D.o: In function `main':
dcmtest.cxx:(.text+0x31): undefined reference to `DicomImage::DicomImage(char const*, unsigned long, unsigned long, unsigned long)'
dcmtest.cxx:(.text+0xaf): undefined reference to `DicomImage::getString(EI_Status)'
/tmp/cchsrh2D.o: In function `DicomImage::setMinMaxWindow(int)':
dcmtest.cxx:(.text._ZN10DicomImage15setMinMaxWindowEi[_ZN10DicomImage15setMinMaxWindowEi]+0x6b): undefined reference to `DiMonoImage::setMinMaxWindow(int)'
collect2: error: ld returned 1 exit status
I tried to include any relevant sections of the library but have not been able to resolve the issue. I am running Ubuntu 16.04 and downloaded DCMTK from the latest snapshot at http://dicom.offis.de/dcmtk.php.en
Do you know what is causing the compilation issue?
As kritzel_sw already wrote: When you use the DicomImage
class from the dcmimgle module, you also have to add the dcmimgle
library to your linker call. By the way, it should be sufficient to include the "dcmtk/dcmimgle/dcmimage.h" header to your sample program, i.e. there's no need for the other DCMTK header files.