linking simple program in C++ VS2005

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
johnmann56
Posts: 7
Joined: Fri, 2006-01-27, 06:53

linking simple program in C++ VS2005

#1 Post by johnmann56 »

:cry:
Hello all. I'm trying to build the following program in VS2005;

Code: Select all

// writeDCMfile1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "dcmtk/dcmdata/dctk.h" 
#include "dcmtk/dcmdata/dcvrobow.h"

int _tmain(int argc, _TCHAR* argv[])
{
	string FILE_NAME = "C:\\Fuji S3\\Convert Program\\Images_5-25-05\\dogLeg2.bmp";
	char uid[10] = {'J'}; 
	Uint8 dataArray[1000];
	DcmFileFormat fileformat; 
	DcmDataset *dataset = fileformat.getDataset();
	dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage); 
	dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT)); 
	dataset->putAndInsertString(DCM_PatientsName, "Doe^John"); 
	/* ... */ 
	/*dataset->putAndInsertUint8Array(DCM_PixelData, dataArray, 1000); */
	dataset->putAndInsertUint8Array(DCM_PixelData, NULL, 0); 
	OFCondition status = fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit); 
	if (status.bad()) 
	  cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;
	return 0;
}
and get "eine gute Menge" linking errors;

>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall DcmFileFormat::~DcmFileFormat(void)" (??1DcmFileFormat@@UAE@XZ) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: virtual class OFCondition __thiscall DcmFileFormat::saveFile(char const *,enum E_TransferSyntax,enum E_EncodingType,enum E_GrpLenEncoding,enum E_PaddingEncoding,unsigned long,unsigned long,bool)" (?saveFile@DcmFileFormat@@UAE?AVOFCondition@@PBDW4E_TransferSyntax@@W4E_EncodingType@@W4E_GrpLenEncoding@@W4E_PaddingEncoding@@KK_N@Z) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: class OFCondition __thiscall DcmItem::putAndInsertUint8Array(class DcmTag const &,unsigned char const *,unsigned long,bool)" (?putAndInsertUint8Array@DcmItem@@QAE?AVOFCondition@@ABVDcmTag@@PBEK_N@Z) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "char * __cdecl dcmGenerateUniqueIdentifier(char *,char const *)" (?dcmGenerateUniqueIdentifier@@YAPADPADPBD@Z) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: __thiscall DcmTag::~DcmTag(void)" (??1DcmTag@@QAE@XZ) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: class OFCondition __thiscall DcmItem::putAndInsertString(class DcmTag const &,char const *,bool)" (?putAndInsertString@DcmItem@@QAE?AVOFCondition@@ABVDcmTag@@PBD_N@Z) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: __thiscall DcmTag::DcmTag(class DcmTagKey const &)" (??0DcmTag@@QAE@ABVDcmTagKey@@@Z) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: class DcmDataset * __thiscall DcmFileFormat::getDataset(void)" (?getDataset@DcmFileFormat@@QAEPAVDcmDataset@@XZ) referenced in function _wmain
1>writeDCMfile1.obj : error LNK2019: unresolved external symbol "public: __thiscall DcmFileFormat::DcmFileFormat(void)" (??0DcmFileFormat@@QAE@XZ) referenced in function _wmain
1>C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug\writeDCMfile1.exe : fatal error LNK1120: 9 unresolved externals

I'm using VS2005. I've tried using /MTd and /MDd both. My solution folder is in the "C:\DCMTK\dcmtk-3.5.4" folder, for good measure. My "Additional Libraries Directory" entry is

..\$(OutDir),..\,..\..\ofstd\$(OutDir),..\..\ofstd\,..\..\dcmdata\$(OutDir),..\..\dcmdata\,..\..\dcmimgle\$(OutDir),..\..\dcmimgle\,..\..\ofstd\libsrc\$(OutDir),..\..\ofstd\libsrc\,..\..\dcmdata\libsrc\$(OutDir),..\..\dcmdata\libsrc\,..\..\dcmimgle\libsrc\$(OutDir),..\..\dcmimgle\libsrc\,..\libsrc\$(OutDir),..\libsrc\

i.e., copied from one of the apps projects in DCMTK. Here is the C++ command line

/Od /I "..\..\config\include" /I "..\include" /I "..\..\ofstd\include" /I "..\..\dcmdata\include" /I "..\..\dcmimgle\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FD /EHsc /MTd /Yc"stdafx.h" /Fp"Debug\writeDCMfile1.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt

and here is the linking command line

/OUT:"C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug\writeDCMfile1.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"..\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\\" /LIBPATH:"..\..\ofstd\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\ofstd\\" /LIBPATH:"..\..\dcmdata\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmdata\\" /LIBPATH:"..\..\dcmimgle\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmimgle\\" /LIBPATH:"..\..\ofstd\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\ofstd\libsrc\\" /LIBPATH:"..\..\dcmdata\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmdata\libsrc\\" /LIBPATH:"..\..\dcmimgle\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmimgle\libsrc\\" /LIBPATH:"..\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\libsrc\\" /MANIFEST /MANIFESTFILE:"Debug\writeDCMfile1.exe.intermediate.manifest" /DEBUG /ASSEMBLYDEBUG /PDB:"c:\DCMTK\dcmtk-3.5.4\writeDCMfile1\debug\writeDCMfile1.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT netapi32.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

Any help would be GREATLY appreciated.

John

Markus Sabin
Posts: 99
Joined: Tue, 2005-07-12, 13:50
Location: Erlangen, Germany

#2 Post by Markus Sabin »

Hi John,

you need to add the dcmtk libraries (in this case: dcmdata and ofstd) to your project's linker options (Project properties -> Linker -> Input -> Additional Dependencies)

HTH

Markus

johnmann56
Posts: 7
Joined: Fri, 2006-01-27, 06:53

#3 Post by johnmann56 »

:idea:
Thank you Marcus. That did indeed help! I then proceeded to get a bunch of errors saying that a bunch of symbols were multiply defined, so I had "it" (VS2005) ignore LIBCMT.LIB and LIBCMTD.LIB. That led to errors like the following;


1>dcmdata.lib(dcuid.obj) : error LNK2001: unresolved external symbol ___security_cookie
1>libcpmtd.lib(locale0.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>libcpmtd.lib(cout.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>ofstd.lib(ofdatime.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>ofstd.lib(ofdate.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>libcpmtd.lib(cerr.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>libcpmtd.lib(string.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>ofstd.lib(ofcrc32.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3
1>ofstd.lib(ofstd.obj) : error LNK2019: unresolved external symbol ___CxxFrameHandler3 referenced in function "public: static void __cdecl OFStandard::ftoa(char *,unsigned int,double,unsigned int,int,int)" (?ftoa@OFStandard@@SAXPADINIHH@Z)
1>ofstd.lib(oflist.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler3


which is where I am now. I must also say that I added full-path references to C:\DCMTK\dcmtk-3.5.4\dcmdata\libsrc\debug and C:\DCMTK\dcmtk-3.5.4\ofstd\libsrc\debug to get it to work, so that my link line now looks like

/OUT:"C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug\writeDCMfile1.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"..\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\\" /LIBPATH:"..\..\ofstd\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\ofstd\\" /LIBPATH:"C:\DCMTK\dcmtk-3.5.4\ofstd\libsrc\debug" /LIBPATH:"C:\DCMTK\dcmtk-3.5.4\ofstd\\" /LIBPATH:"..\..\dcmdata\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmdata\\" /LIBPATH:"C:\DCMTK\dcmtk-3.5.4\dcmdata\libsrc\debug" /LIBPATH:"C:\DCMTK\dcmtk-3.5.4\dcmdata\\" /LIBPATH:"..\..\dcmimgle\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmimgle\\" /LIBPATH:"..\..\ofstd\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\ofstd\libsrc\\" /LIBPATH:"..\..\dcmdata\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmdata\libsrc\\" /LIBPATH:"..\..\dcmimgle\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\..\dcmimgle\libsrc\\" /LIBPATH:"..\libsrc\C:\DCMTK\dcmtk-3.5.4\writeDCMfile1\Debug" /LIBPATH:"..\libsrc\\" /MANIFEST /MANIFESTFILE:"Debug\writeDCMfile1.exe.intermediate.manifest" /NODEFAULTLIB:"LIBCMT.lib" /NODEFAULTLIB:"LIBCMTD.lib" /DEBUG /ASSEMBLYDEBUG /PDB:"c:\DCMTK\dcmtk-3.5.4\writeDCMfile1\debug\writeDCMfile1.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT netapi32.lib wsock32.lib dcmdata.lib ofstd.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

I'd add an emoticon for "less likely now to go on a murderous rampage", but it seems to be missing... Thanks for any additional help.

John

Markus Sabin
Posts: 99
Joined: Tue, 2005-07-12, 13:50
Location: Erlangen, Germany

#4 Post by Markus Sabin »

Hi John,

I' not sure, but it looks as if exception handling is disabled for at least one of your projects. Most likely, the problem is in CMakeLists.txt. Make sure, that the /EHsc option is set in CMAKE_CXX_FLAGS for all configurations (Debug, Release, ...)

If you do not use Exception handling, disable it for the exe-Project (Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Enable C++ Exceptions)

Regards

Markus

Michael Onken
DCMTK Developer
Posts: 2055
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#5 Post by Michael Onken »

Hi John,

I'm not able to help you with the compiler errors, but I've noticed, that you didn't "install" the DCMTK. If you are using Visual C++ (or lookalikes) you see the Install-target in the target list. This target copies all includes, libs etc. to a better directory structure for development of new applications. You just need then one LIB directory and one include path in your compiler settings for compiling your application :o

You're compiler error seems to originate from a wrong library path setting, I've just googled and found this hint on the Microsoft website.

Good luck, hope your "murderous rampage"-mood can be becalmed to the weekend, otherwise send us a proposed emoticon :)

Regards,
Michael

johnmann56
Posts: 7
Joined: Fri, 2006-01-27, 06:53

#6 Post by johnmann56 »

... too tired to emote ...

After following your suggestion to actually FOLLOW THE DIRECTIONS and also checking the 3 unchecked boxes in Project -> Configuration menu of the Solution in VS2005, everything was peachy. Thank you Michael.

John[/code]

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests