Questions on DCM File TAG Modification and LNK2019 Error

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
via
Posts: 4
Joined: Mon, 2023-12-18, 09:28

Questions on DCM File TAG Modification and LNK2019 Error

#1 Post by via »

I'm having some questions with the latest version(2023/10/27) of master branch on git:

Question1:
I need to change the TAG of a dcm file. I open the file using the "loadFile" interface, then I change the TAG through the "putAndInsertString" interface, and finally I save the file by calling the "saveFile" interface.
After saving the file, I found that the TAG(0002,0016) was removed from the new file. If the original dcm file already contained this TAG, then the new file should also contain that TAG.
I tried using a different "writeMode" when using the "saveFile" interface, but the result is the same.

Question2:
I took the compiled lib and referenced it with an MFC EXE, and when compiling the EXE program VS reported this error: error LNK2019: _libiconv_open, _libiconv, _libiconv_close...
In compiling DCMTK with CMake, I changed some options:
DCMTK_COMPILE_WIN32_MULTITHREADED_DLL is set to on.
DCMTK_ENABLE_CHARSET_CONVERSION is set to libiconv.
DCMTK_WITH_ICONV, DCMTK_WITH_OPENJPEG, DCMTK_WITH_LIBPNG, DCMTK_WITH_TIFF, DCMTK_WITH_LIBXML are also checked.
In the With Group also set the path to the corresponding components, these support libraries I extracted from dcmtk-3.6.7-win32-support-MT-iconv-msvc-17.0

I don't know how these problem should be solved.
Any help would be appreciated.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Questions on DCM File TAG Modification and LNK2019 Error

#2 Post by Marco Eichelberg »

Concerning your first question: (0002,0016) Source Application Entity Title is an attribute that must only appear in the metaheader, never in the main dataset - it is forbidden there. Try writing it to the metaheader instead of the main dataset.

Concerning the second question: If you are compiling with libiconv, then you also need to link with libiconv. Note that there are two libiconv instances in the pre-compiled support libraries for DCMTK 3.6.7: One is in the libiconv directory, the other one in the libxml2 directory, which needs its own version.

via
Posts: 4
Joined: Mon, 2023-12-18, 09:28

Re: Questions on DCM File TAG Modification and LNK2019 Error

#3 Post by via »

Hello,

First question:

If that TAG existed in the old file, it should normally remain in the new file as well. Also, I changed the DCM_SourceApplicationEntityTitle with metaInfo, but it still doesn't work.

Code: Select all

int EditDcm(const char* OldFile, const char* NewFile) 
{
	DcmFileFormat fileformat;
	if (!fileformat.loadFile(OldFile).good()) {

		return -1;
	}

	DcmDataset* dataset = fileformat.getDataset();
	DcmMetaInfo* metaInfo = fileformat.getMetaInfo();
	
	if (metaInfo->putAndInsertString(DCM_SourceApplicationEntityTitle, "AETitle").bad())
	{
		return -1;
	}
	if (!fileformat.saveFile(NewFile).good())
	{
		return -1;
	}
	return 0;
}
Second Question:
I set the include path for libiconv in CMake to dcmtk-3.6.7-win32-support-MT-iconv-msvc-17.0\libiconv-1.16, but even then I can't compile it?
So what should I do to make DCMTK include precompiled libraries for libiconv and libxml2, I can't find anything related to libxml2 in the dcmtk-3.6.7-win32-support-mt-iconv-msvc-17.0 zip.

Thanks.
Marco Eichelberg wrote: Mon, 2023-12-18, 16:40 Concerning your first question: (0002,0016) Source Application Entity Title is an attribute that must only appear in the metaheader, never in the main dataset - it is forbidden there. Try writing it to the metaheader instead of the main dataset.

Concerning the second question: If you are compiling with libiconv, then you also need to link with libiconv. Note that there are two libiconv instances in the pre-compiled support libraries for DCMTK 3.6.7: One is in the libiconv directory, the other one in the libxml2 directory, which needs its own version.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Questions on DCM File TAG Modification and LNK2019 Error

#4 Post by Marco Eichelberg »

Also, I changed the DCM_SourceApplicationEntityTitle with metaInfo, but it still doesn't work.
Check the API documentation for DcmFileFormat::writeFile() at https://support.dcmtk.org/docs/classDcmFileFormat.html. By default, the content of the meta-header is discarded and a new meta-header is created. The parameter "writeMode" controls this behaviour. You may want to pass "EWM_dontUpdateMeta" as a value here.
If that TAG existed in the old file, it should normally remain in the new file as well.
I agree. I checked the code again, and it seems that group 0002 attributes will only be removed from the main dataset when DcmFileFormat::removeInvalidGroups() is called explicitly by the user.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Questions on DCM File TAG Modification and LNK2019 Error

#5 Post by Marco Eichelberg »

I set the include path for libiconv in CMake to dcmtk-3.6.7-win32-support-MT-iconv-msvc-17.0\libiconv-1.16, but even then I can't compile it?
The problem is not the include path, but the libraries, since this is a linker error and not a compiler error.
For libiconv, you need to link your code against libiconv_o.lib and charset_o.lib, for libxml2 you need to link your code against iconv_o.lib and libxml2_o.lib.

via
Posts: 4
Joined: Mon, 2023-12-18, 09:28

Re: Questions on DCM File TAG Modification and LNK2019 Error

#6 Post by via »

Okay, I understand. I will link libiconv_d.lib after linking the lib of dcmtk.
Thank you very much.
Marco Eichelberg wrote: Sun, 2023-12-24, 18:23
I set the include path for libiconv in CMake to dcmtk-3.6.7-win32-support-MT-iconv-msvc-17.0\libiconv-1.16, but even then I can't compile it?
The problem is not the include path, but the libraries, since this is a linker error and not a compiler error.
For libiconv, you need to link your code against libiconv_o.lib and charset_o.lib, for libxml2 you need to link your code against iconv_o.lib and libxml2_o.lib.

via
Posts: 4
Joined: Mon, 2023-12-18, 09:28

Re: Questions on DCM File TAG Modification and LNK2019 Error

#7 Post by via »

Thanks for your reply, using EWM_dontUpdateMeta mode solves the problem.
But I have a new question, if I want the DCM_ImplementationVersionName TAG of the meta information when I save the file to be set according to OFFIS_DTK_IMPLEMENTATION_VERSION_NAME in the dcmtk, is it possible to realize such a function?

Marco Eichelberg wrote: Sun, 2023-12-24, 18:16
Also, I changed the DCM_SourceApplicationEntityTitle with metaInfo, but it still doesn't work.
Check the API documentation for DcmFileFormat::writeFile() at https://support.dcmtk.org/docs/classDcmFileFormat.html. By default, the content of the meta-header is discarded and a new meta-header is created. The parameter "writeMode" controls this behaviour. You may want to pass "EWM_dontUpdateMeta" as a value here.
If that TAG existed in the old file, it should normally remain in the new file as well.
I agree. I checked the code again, and it seems that group 0002 attributes will only be removed from the main dataset when DcmFileFormat::removeInvalidGroups() is called explicitly by the user.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: Questions on DCM File TAG Modification and LNK2019 Error

#8 Post by Marco Eichelberg »

This is what DCMTK does by default. If you use EWM_dontUpdateMeta, you have to insert this tag in the metaheader dataset yourself, e.g.

Code: Select all

fileformat.getMetaInfo()->putAndInsertString(DCM_ImplementationVersionName, OFFIS_DTK_IMPLEMENTATION_VERSION_NAME, OFTrue);

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 1 guest