I am trying to install the dcmtk library on Visual Studio 2022. I have downloaded the source code and the Pre-compiled libraries for Visual Studio 2022 (MSVC 17.4), 64 bit, with "MT" option support libraries.
Then, through CMake, I have generated the Visual Studio project which I have built and installed correctly.
I set in the solution Property Pages the include and library directories (VC++ Directories) as well as the following Additional Dependencies in Linker -> Input:
ofstd.lib
oflog.lib
Iphlpapi.lib
ws2_32.lib
wsock32.lib
netapi32.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
ijg8.lib
ijg12.lib
ijg16.lib
i2d.lib
zlib_d.lib
Now, I am trying to run a simple example to see if everything works fine:
#include <iostream>
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/dcmimage.h"
using namespace std;
int main(int argc, const char *argv[]) {
string in_file = "C:\\Users\\windows\\Desktop\\CQ500CT0 CQ500CT0\\Unknown Study\\CT 4cc sec 150cc D3D on\\CT000000.dcm";
// Initialize DCMTK
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("path_to_your_dicom_file.dcm");
if (status.good()) {
// Access the dataset
DcmDataset* dataset = fileformat.getDataset();
// Print some basic information
OFString patientName;
if (dataset->findAndGetOFString(DCM_PatientName, patientName).good()) {
std::cout << "Patient's Name: " << patientName << std::endl;
}
else {
std::cerr << "Error: cannot access Patient's Name!" << std::endl;
}
}
else {
std::cerr << "Error: cannot read DICOM file (" << status.text() << ")" << std::endl;
}
return 0;
}
However, I receive some errors due to unresolved external symbols:
Severity Code Description Project File Line Suppression State Details
Error LNK1120 5 unresolved externals DicomTest C:\Users\windows\source\repos\DicomTest\x64\Release\DicomTest.exe 1
Error LNK2001 unresolved external symbol libiconv_open DicomTest C:\Users\windows\source\repos\DicomTest\DicomTest\ofstd.lib(ofchrenc.obj) 1
Error LNK2001 unresolved external symbol libiconv DicomTest C:\Users\windows\source\repos\DicomTest\DicomTest\ofstd.lib(ofchrenc.obj) 1
Error LNK2001 unresolved external symbol libiconv_close DicomTest C:\Users\windows\source\repos\DicomTest\DicomTest\ofstd.lib(ofchrenc.obj) 1
Error LNK2001 unresolved external symbol libiconvctl DicomTest C:\Users\windows\source\repos\DicomTest\DicomTest\ofstd.lib(ofchrenc.obj) 1
Error LNK2001 unresolved external symbol locale_charset DicomTest C:\Users\windows\source\repos\DicomTest\DicomTest\ofstd.lib(ofchrenc.obj) 1
The only options that I changed in the CMAKE configuration are the default oficonv option in DCMTK_ENABLE_CHARSET_CONVERSION for which I have tried also libiconv option without changes and obvsiously I have specified the DCMTK_SUPPORT_LIBRARIES_DIR pointing to the previous downloaded support libraries.
For the former, I have specified the libiconv-1.15 files folder in WITH_LIBICONVINV entry and flagged the DCMTK_WITH_ICONV to True.
libiconv
libraries (libiconv.lib
and libiconv_d.lib
) are included in your linker's "Additional Dependencies" under "Input".libiconv
libraries is specified correctly in your project's properties.libiconv
is linked correctly, there might be a mismatch between the version you're using and the one DCMTK was built with. Try rebuilding DCMTK with the same version of libiconv
you have installed.After this, you should be able to resolve the linker errors and successfully use the DCMTK library in your Visual Studio project.