undefined reference for dcmtk libraries

Compilation and installation of DCMTK

Moderator: Moderator Team

Message
Author
karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

undefined reference for dcmtk libraries

#1 Post by karatystas »

I have compiled DCMTK 3.6.0 with Visual Studio 2008 and trying to include it in Qt creator framework. However, when I try to compile the program I get the following error:
error: undefined reference to `DicomImage::DicomImage(char const*, unsigned long, unsigned long, unsigned long)'
main.cpp:

Code: Select all

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmimgle/dcmimage.h"
#include "iostream"

int main(int argc, char *argv[])
{

    DicomImage *image = new DicomImage("test.dcm");
    if (image != NULL){
        std::cout << "hell yeah!";
    }

    return 0;
}
.pro file:

Code: Select all

#-------------------------------------------------
#
# Project created by QtCreator 2016-02-18T19:16:51
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled1
TEMPLATE = app


SOURCES += main.cpp
        #mainwindow.cpp

#HEADERS  += mainwindow.h

#FORMS    += mainwindow.ui

#--------------------------------
CONFIG += c++11
#--------------------------------
LIBS += -L"C:\Program Files (x86)\DCMTK_1\lib"
LIBS +=-ldcmimgle -ldcmdata -loflog -lofstd

win32:LIBS += -lAdvAPI32 -lofstd -loflog -ldcmdata -ldcmnet -ldcmimage -ldcmimgle -lWS2_32 -lNetAPI32 -lWSock32
INCLUDEPATH += "C:\Program Files (x86)\DCMTK_1\include"
I also copied libraries AdvAPI32, WS2_32, NetAPI32 and WSock32 to DCMTK lib folder from Windows SDK folder. I think I have the correct order of libraries as was stated in FAQ #27, however I can't make it work in anyway. What is the problem? I'm using Windows 7 x64.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#2 Post by J. Riesmeier »

Not sure whether the "LIBS" or "win32:LIBS" line of your .pro file is actually used, but the order of libraries in "win32:LIBS" seems to be wrong: first dcmimgle, then dcmimage. You could also try to omit "dcmimage" since you did not register support for color images in your sample program.

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#3 Post by karatystas »

I have tried everything you said and still doesn't work. Now I only have these two lines in my .pro file:

Code: Select all

INCLUDEPATH += C:/DCMTK/include

LIBS += -L"C:/DCMTK/lib" -lAdvAPI32 -ldcmimgle -ldcmdata -loflog -lofstd -lWS2_32 -lNetAPI32 -lWSock32
I have also tried to remove the LIBS line at all and the effect was the same - looks like it completely doesn't include those lib files.

The tree of the compiled version of dcmtk looks like:

Image
http://imgur.com/YRDjA02

Maybe I have compiled it wrongly? I used Visual Studio 2008 and build for DEBUG and win32.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#4 Post by J. Riesmeier »

Enabling the verbose mode of the linker should give you more details...

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#5 Post by karatystas »

Sorry for stupid question but where should I enable it? In Qt creator?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#6 Post by J. Riesmeier »

I would do this in "Visual Studio 2008" (see documentation).

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#7 Post by karatystas »

I enabled detailed verbose mode however it doesn't provide neither errors nor warnings. Everything builds successfully.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#8 Post by J. Riesmeier »

That means, problem solved?

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#9 Post by karatystas »

Perhaps means that dcmtk libraries are build successfully but still I cannot make it work in Qt creator.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#10 Post by J. Riesmeier »

Can't you enable the verbose linker output in "Qt creator", i.e. when linking the DCMTK libraries to your program?

Maybe, you can find the answer here: http://doc.qt.io/qtcreator/creator-build-settings.html

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#11 Post by karatystas »

I have just tried to execute the example app provided in FAQ #40 with Visual Studio 2008.

I got the following errors:

Code: Select all

1>------ Build started: Project: testapp, Configuration: Debug Win32 ------
1>Compiling...
1>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>cl /Od /I "C:\DCMTK\include" /D "_REENTRANT" /D "CMAKE_INTDIR=\"Debug\"" /D "_MBCS" /FD /EHsc /MTd /Gy /Fo"testapp.dir\Debug\\" /Fd"testapp.dir\Debug\vc90.pdb" /W3 /c /Z7 /TP   /YX
1>   ..\testapp\testapp.cxx
1>cl : Command line warning D9002 : ignoring unknown option '/YX'
1>testapp.cxx
1>C:\DCMTK\include\dcmtk/ofstd/offile.h(200) : error C2039: 'popen' : is not a member of '`global namespace''
1>C:\DCMTK\include\dcmtk/ofstd/offile.h(200) : error C2440: '=' : cannot convert from 'bool' to 'FILE *'
1>        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>C:\DCMTK\include\dcmtk/ofstd/offile.h(262) : error C2039: 'pclose' : is not a member of '`global namespace''
1>C:\DCMTK\include\dcmtk/ofstd/offile.h(262) : error C2660: 'OFFile::pclose' : function does not take 1 arguments
1>..\testapp\testapp.cxx(11) : error C2065: 'DCM_PatientsName' : undeclared identifier
1>..\testapp\testapp.cxx(11) : error C2228: left of '.good' must have class/struct/union
1>..\testapp\testapp.cxx(13) : error C2065: 'cout' : undeclared identifier
1>..\testapp\testapp.cxx(13) : error C2065: 'endl' : undeclared identifier
1>..\testapp\testapp.cxx(15) : error C2065: 'cerr' : undeclared identifier
1>..\testapp\testapp.cxx(15) : error C2065: 'endl' : undeclared identifier
1>..\testapp\testapp.cxx(17) : error C2065: 'cerr' : undeclared identifier
1>..\testapp\testapp.cxx(17) : error C2065: 'endl' : undeclared identifier
1>Build log was saved at "file://c:\Users\Donn\Desktop\install\testapp.dir\Debug\BuildLog.htm"
1>testapp - 12 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
Do not know where to start from in order to solve it...

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#12 Post by J. Riesmeier »

The FAQ #40 entry refers to DCMTK 3.5.4, which is more than 10 years old.

What about FAQ #47: "How do I use the latest (snapshot) DCMTK libraries in my own application? [MSVC]"
However, be warned that "Visual Studio 2008" does not seem to be checked by the listed CMake file...

I guess the preferred way of using DCMTK in your own program (with support of CMake) is the one described here: http://support.dcmtk.org/redmine/projec ... akeExports
Last edited by J. Riesmeier on Fri, 2016-02-19, 18:40, edited 2 times in total.

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#13 Post by karatystas »

Actually only the Visual Studio 2008 provided me compilation of libraries without any errors or warnings. The versions of 2010, 2013 or later yields some errors and warnings. I will try to run snapshot version with VS2015.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: undefined reference for dcmtk libraries

#14 Post by J. Riesmeier »

DCMTK 3.6.0 should work with VisualStudio 2010 (32-bit mode), as this compiler is listed in the INSTALL file.

But since this DCMTK release is already more than 5 years old, I would also recommend to use the latest development snapshot (from this week).

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: undefined reference for dcmtk libraries

#15 Post by karatystas »

Tried snapshot with VS15 and building the example you provided received many errors like:

Code: Select all

2>------ Build started: Project: testapp, Configuration: Debug Win32 ------
2>Build started 2/19/2016 9:02:41 PM.
2>     1>
2>PrepareForBuild:
2>         Creating directory "testapp.dir\Debug\testapp.tlog\".
2>       InitializeBuildStatus:
2>         Creating "testapp.dir\Debug\testapp.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
2>       CustomBuild:
2>         Building Custom Rule C:/Users/Donn/Desktop/testapp/CMakeLists.txt
2>         CMake does not need to re-run because C:\Users\Donn\Desktop\install\CMakeFiles\generate.stamp is up-to-date.
2>       ClCompile:
2>         Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
2>         Copyright (C) Microsoft Corporation.  All rights reserved.
2>
2>         cl /c /IC:\DCMTK\include /Zi /W3 /WX- /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D _DEBUG /D _REENTRANT /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"testapp.dir\Debug\\" /Fd"testapp.dir\Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:prompt C:\Users\Donn\Desktop\testapp\testapp.cxx
2>
2>         testapp.cxx
2>       Link:
2>         Microsoft (R) Incremental Linker Version 14.00.23506.0
2>         Copyright (C) Microsoft Corporation.  All rights reserved.
2>
2>         "/OUT:C:\Users\Donn\Desktop\install\Debug\testapp.exe" /INCREMENTAL /LIBPATH:C:/DCMTK/lib /LIBPATH:C:/DCMTK/lib/Debug kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib dcmdata.lib oflog.lib ofstd.lib ws2_32.lib netapi32.lib wsock32.lib /MANIFEST "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG "/PDB:C:/Users/Donn/Desktop/install/Debug/testapp.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:C:/Users/Donn/Desktop/install/Debug/testapp.lib" /MACHINE:X86 /SAFESEH /machine:X86 /debug testapp.dir\Debug\testapp.obj
2>     1>
2>dcmdata.lib(dcitem.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dcfilefo.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dcvr.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dcxfer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dctagkey.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dctag.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dcstack.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
2>dcmdata.lib(dcobject.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in testapp.obj
2>     1>
Also, compiling dcmtk libraries received multiple warnings.

Post Reply

Who is online

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