error LNK2019: unresolved external symbol

Compilation and installation of DCMTK

Moderator: Moderator Team

Message
Author
Clayton Vasconcelos
Posts: 3
Joined: Fri, 2007-07-13, 21:45

error LNK2019: unresolved external symbol

#1 Post by Clayton Vasconcelos »

I've Installed the DCMTK under Visual Studio 2005 (VC++). I got success on installation. But when a try to create a easy applicatiton to teste I have some problems.


Source Code:

#include "dcmtk/config/cfwin32.h"
#include "dcmtk/dcmimgle/dcmimage.h"



// Declaration ------------------------------------------------------
void ReadImageDCM(char *Path);



// ReadImageDCM ----------------------------------------------------------
void ReadImageDCM(char *Path)
{
DicomImage *image = new DicomImage(Path);
if (image != NULL)
{
if (image->getStatus() == EIS_Normal)
{
Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits per sample */));
if (pixelData != NULL)
{
/* do something useful with the pixel data */
}
} else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;

}


Error:

------ Build started: Project: myDCMTK, Configuration: Debug Win32 ------
Compiling...
myDCMTK.cpp
Linking...
Creating library C:\Documents and Settings\Administrador\Desktop\myDCMTK\Debug\myDCMTK.lib and object C:\Documents and Settings\Administrador\Desktop\myDCMTK\Debug\myDCMTK.exp
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function "long __cdecl gethostid(void)" (?gethostid@@YAJXZ)
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function "long __cdecl gethostid(void)" (?gethostid@@YAJXZ)
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _gethostname@8 referenced in function "long __cdecl gethostid(void)" (?gethostid@@YAJXZ)
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function "long __cdecl gethostid(void)" (?gethostid@@YAJXZ)
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _Netbios@4 referenced in function "unsigned char * __cdecl getMACAddress(unsigned char * const)" (?getMACAddress@@YAPAEQAE@Z)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\Administrador\Desktop\myDCMTK\Debug\myDCMTK.exe : fatal error LNK1120: 6 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Administrador\Desktop\myDCMTK\Debug\BuildLog.htm"
myDCMTK - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Help me people!

Thanks a lot for everything
Clayton DCM

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

#2 Post by Marco Eichelberg »

See FAQ #27. Although the linker error in your case is 2019, not 2001, the article applies as well.

Clayton Vasconcelos
Posts: 3
Joined: Fri, 2007-07-13, 21:45

#3 Post by Clayton Vasconcelos »

Where may I set the sequence?
Clayton DCM

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

#4 Post by Michael Onken »

Hi,

right-click on your project in the solution explorer, select properties, then "Configuration Properties", then Linker. You then can enter all libraries that should be linked in the "Input" line, using your desired linking order.

Regards,
Michael

smfmazz
Posts: 7
Joined: Mon, 2010-09-06, 17:19

#5 Post by smfmazz »

Hi, i taje this opportunity for explain my problem. I think to have the same problem:
error LNK2019: riferimento al simbolo esterno "public: virtual __thiscall DcmFileFormat::~DcmFileFormat(void)" (??1DcmFileFormat@@UAE@XZ) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "public: __thiscall OFString::~OFString(void)" (??1OFString@@QAE@XZ) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class OFString const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVOFString@@@Z) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "public: class OFCondition __thiscall DcmItem::findAndGetOFString(class DcmTagKey const &,class OFString &,unsigned long,bool)" (?findAndGetOFString@DcmItem@@QAE?AVOFCondition@@ABVDcmTagKey@@AAVOFString@@K_N@Z) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "public: class DcmDataset * __thiscall DcmFileFormat::getDataset(void)" (?getDataset@DcmFileFormat@@QAEPAVDcmDataset@@XZ) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "public: __thiscall OFString::OFString(void)" (??0OFString@@QAE@XZ) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "public: virtual class OFCondition __thiscall DcmFileFormat::loadFile(char const *,enum E_TransferSyntax,enum E_GrpLenEncoding,unsigned long,enum E_FileReadMode)" (?loadFile@DcmFileFormat@@UAE?AVOFCondition@@PBDW4E_TransferSyntax@@W4E_GrpLenEncoding@@KW4E_FileReadMode@@@Z) non risolto nella funzione _main
1>provadcmtkallamia.obj : error LNK2019: riferimento al simbolo esterno "public: __thiscall DcmFileFormat::DcmFileFormat(void)" (??0DcmFileFormat@@QAE@XZ) non risolto nella funzione _main
1>C:\Users\Mirko\Documents\Tesi\provadcmtk\provadcmtkallamia\Debug\provadcmtkallamia.exe : fatal error LNK1120: 8 esterni non risolti

I added at the linker the library netapi32.lib and wsock32.lib but the situation doesn't change.

I also have an other question: in the example
#include "stdafx.h"


#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"

int main()
{
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("test.dcm");
if (status.good())
{
OFString patientsName;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientsName, patientsName).good())
{
cout << "Patient's Name: " << patientsName << endl;
} else
cerr << "Error: cannot access Patient's Name!" << endl;
} else
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
return 0;
}

In visual studio, i do insert the header file (dsconfig.h and dctk.h) in the directory of header file? The directory dcmtk (with subdirectory config and dcmdata) is stored in the project directory... Is correct?
Thanks

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

#6 Post by Michael Onken »

Hi,

are you linking to dcmdata, oflog and ofstd? In the correct order?

Best regards,
Michael

smfmazz
Posts: 7
Joined: Mon, 2010-09-06, 17:19

#7 Post by smfmazz »

Thank you! I have understand the problem

zezba9000
Posts: 2
Joined: Thu, 2010-12-09, 00:25

#8 Post by zezba9000 »

Where you ever able to find the order in which the library's should be ordered?

My current order is ::
{
dcmpstat.lib
ijg8.lib
ijg12.lib
ijg16.lib
dcmjpeg.lib
dcmimage.lib
dcmimgle.lib
dcmdsig.lib
dcmqrdb.lib
dcmtls.lib
dcmwlm.lib
dcmnet.lib
dcmsr.lib
dcmdata.lib
ofstd.lib
}

Is this incorrect??

zezba9000
Posts: 2
Joined: Thu, 2010-12-09, 00:25

#9 Post by zezba9000 »

Never mind I got it working. I didn't include "netapi32.lib" and "wsock32.lib"

Mitmal
Posts: 112
Joined: Mon, 2011-04-18, 19:36
Location: France

#10 Post by Mitmal »

I don't understand what I have to do here.
I use Visual Studio 2010 and I don't understand where I have to add this information.

I suppose I must to add this ligne :

Code: Select all

dcmdata.lib; ofstd.lib;dcmimage.lib; dcmimgle.lib; dcmdata.lib; ofstd.lib;dcmimgle.lib; dcmdata.lib; ofstd.lib;dcmjpeg.lib; ijg8.lib; ijg12.lib; ijg16.lib; dcmimage.lib; dcmimgle.lib; dcmdata.lib; ofstd.lib;dcmnet.lib; dcmdata.lib; ofstd.lib;dcmpstat.lib; dcmimage.lib; dcmimgle.lib;; dcmsign.lib;; dcmsr.lib;; imagectn.lib; dcmtls.lib; dcmnet.lib; dcmdata.lib; ofstd.lib;dcmsign; dcmdata.lib; ofstd.lib;dcmsr; dcmdata.lib; ofstd.lib;dcmtls; dcmnet.lib; dcmdata.lib; ofstd.lib;dcmwlm; dcmnet.lib; dcmdata.lib; ofstd.lib;dcmqrbd; dcmnet.lib; dcmdata.lib; ofstd.lib;ws2_32.lib;netapi32.lib;qtmaind.lib;QtCored4.lib;QtGuid4.lib;QtMultimediad4.lib;QtXmld4.lib;QtSqld4.lib;QtOpenGLd4.lib;opengl32.lib;glu32.lib;QtNetworkd4.lib;QtScriptd4.lib;Qt3Supportd4.lib;comdlg32.lib;QAxServerd.lib;QtSvgd4.lib;QtHelpd4.lib;QtWebKitd4.lib;QtXmlPatternsd4.lib;QtTestd4.lib;QtDeclaratived4.lib;phonond4.lib;%(AdditionalDependencies)
In my project Properties, maybe in the linker, in the field Input... But I'm not sur !!!

Maybe it's this code which I have to put :

Code: Select all

C:\dcmtk-3.6.0\ofstd\libsrc\Debug;C:\dcmtk-3.6.0\dcmimgle\libsrc\Debug;C:\dcmtk-3.6.0\dcmdata\libsrc\Debug;C:\dcmtk-3.6.0\dcmdata\libi2d\Debug;C:\dcmtk-3.6.0\dcmjpeg\libijg8\Debug;C:\dcmtk-3.6.0\dcmjpeg\libijg12\Debug;C:\dcmtk-3.6.0\dcmjpeg\libijg16\Debug;C:\dcmtk-3.6.0\dcmimage\libsrc\Debug;C:\dcmtk-3.6.0\dcmsign\libsrc\Debug;C:\dcmtk-3.6.0\dcmsr\libsrc\Debug;C:\dcmtk-3.6.0\dcmtls\libsrc\Debug;C:\dcmtk-3.6.0\dcmnet\libsrc\DebugC:\dcmtk-3.6.0\dcmdata\libsrc\Debug;C:\dcmtk-3.6.0\dcmimage\libsrc\Debug;C:\dcmtk-3.6.0\dcmimgle\libsrc\Debug;C:\dcmtk-3.6.0\dcmjpeg\libsrc\Debug;C:\dcmtk-3.6.0\dcmnet\libsrc\Debug;C:\dcmtk-3.6.0\dcmpstat\libsrc\Debug;C:\dcmtk-3.6.0\dcmsign\libsrc\Debug;C:\dcmtk-3.6.0\dcmsr\libsrc\Debug;C:\dcmtk-3.6.0\dcmtls\libsrc\Debug;C:\dcmtk-3.6.0\wlm\libsrc\Debug;C:\dcmtk-3.6.0\dcmqrdb\libsrc\Debug;$(QTDIR)\lib;$(QTDIR)\lib;%(AdditionalLibraryDirectories)
Why is there not a tutorial to explain that ????? :oops:
Respectueusement,
MitMal

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

#11 Post by Michael Onken »

Hi,

this is not specific to DCMTK so we do not have a tutorial for that.

However, in Visual Studio (here: 2008, German version!)
1) right click on your project in the list of projects (here it is on the left side) and click properties
2) Then inside the pop-up window, select Linker
3) Click on the plus next to Linker
4) Go to sub-bullet "Input" and add all libraries needed at the end of the line, for example "dcmnet.lib dcmdata.lib oflog.lib ofstd.lib ws2_32.lib netapi32.lib wsock32.lib"
5) Click another sub-bullet of "Linker", called "General" (first one).
6) There is a line called (well translated from german) "Additional Library directories". Here, add the directory where dcmdata.lib, oflog.lib and so on are stored in. Usually it is a directory called "lib" inside your DCMTK installation directory.
7) Click on the Bullet "C/C++".
8 ) Add the path where all dcmtk include files (.h) are to the line "Additional include directories". This is usually the "include" directory inside your DCMTK installation directory.
9) Click OK :-)

That's it.

Michael

Mitmal
Posts: 112
Joined: Mon, 2011-04-18, 19:36
Location: France

#12 Post by Mitmal »

Thx, but I need to know what exactly put in these fields :(
I found a explaination about the order of the include and the lib; did I add a correct things ???
Respectueusement,
MitMal

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

#13 Post by Michael Onken »

Order of include paths doesn't matter. Order of libraries does. Use them as I quoted them above and this will work.

Michael

ruchir_iit
Posts: 4
Joined: Fri, 2016-11-25, 10:31

Re: error LNK2019: unresolved external symbol

#14 Post by ruchir_iit »

Hi Michael,

I followed the steps listed above but still I get the error message:

dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _Netbios@4 referenced in function "unsigned char * __cdecl getMACAddress(unsigned char * const)" (?getMACAddress@@YAPAEQAE@Z)

Not sure what's going wrong :|

Ruchir

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

Re: error LNK2019: unresolved external symbol

#15 Post by Michael Onken »

Do you build shared libraries (option in cmake) or static? Try static first. Not sure what is going wrong...

Best,
Michael

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest