Compile Sample Program on Linux

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
swaroopcool21
Posts: 12
Joined: Wed, 2011-03-23, 12:40
Location: Alkmaar, The Netherlands
Contact:

Compile Sample Program on Linux

#1 Post by swaroopcool21 »

Hi,
I am using UBUNTU (Linux).

I need to compile and run the sample code (below).
I use g++. Please help me with the command to compile

test.cpp

Code: Select all

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

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

[/code]
---
Manohar Kuse
SenoCAD Research
Alkmaar, The Netherlands

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

#2 Post by Michael Onken »

Hi,

this is the example from the dcmdata documentation.

There are many gcc/g++ tutorials on the internet. Please start with one of those. Generally you will compile somehow like this:

Code: Select all

g++ yourcode.cc -o yourcode
But you will have at least to add -L options with libraries dcmdata, ofstd and oflog and -I options to show g++ where it must look for header files. You may also get an idea if you have a look how g++ is used to compile dcmdump during DCMTK compilation.

Best regards,
Michael

swaroopcool21
Posts: 12
Joined: Wed, 2011-03-23, 12:40
Location: Alkmaar, The Netherlands
Contact:

#3 Post by swaroopcool21 »

I have seen the example.

but following thing is wat i find missing -
1. which include files (headers) to be used
2. compilation instructions (with -L & -I option)

please help me with the exact command
my dcmtk include files lie in /usr/include/dcmtk/

thanks for help
---
Manohar Kuse
SenoCAD Research
Alkmaar, The Netherlands

swaroopcool21
Posts: 12
Joined: Wed, 2011-03-23, 12:40
Location: Alkmaar, The Netherlands
Contact:

#4 Post by swaroopcool21 »

Also,

the example on the DCMTK documentation

has no defination about the symbol

`DCM_PatientName` and `patientName`

please help....
---
Manohar Kuse
SenoCAD Research
Alkmaar, The Netherlands

swaroopcool21
Posts: 12
Joined: Wed, 2011-03-23, 12:40
Location: Alkmaar, The Netherlands
Contact:

#5 Post by swaroopcool21 »

Following is my program --

Code: Select all

#include <iostream>

using namespace std;
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

#include <dcfilefo.h> //in dcmdata
#include <dcitem.h> //in dcmdata


int main()
{
    DcmFileFormat fileformat;
    OFCondition status = fileformat.loadFile("test.dcm");
    if (status.good())
    {
      OFString patientName;
      if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
      {
        cout << "Patient's Name: " << patientName << endl;
      } else
        cerr << "Error: cannot access Patient's Name!" << endl;
    } 
    else
      cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
      
}
I use following command for compilation on linux

Code: Select all

g++ -I/usr/include/dcmtk/dcmdata -o testProgram testProgram.cc 
My dcmtk include files lie in the directory /usr/include/dcmtk

But, I get following error from the compiler.

Code: Select all


In file included from /usr/include/dcmtk/ofstd/ofconsol.h:68,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:39,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofstream.h:63:22: error: iostream.h: No such file or directory
/usr/include/dcmtk/ofstd/ofstream.h:64:21: error: fstream.h: No such file or directory
/usr/include/dcmtk/ofstd/ofstream.h:76:2: error: #error DCMTK needs stringstream or strstream type
/usr/include/dcmtk/ofstd/ofstream.h:78:21: error: iomanip.h: No such file or directory
In file included from /usr/include/dcmtk/dcmdata/dcpcache.h:39,
                 from /usr/include/dcmtk/dcmdata/dcitem.h:45,
                 from /usr/include/dcmtk/dcmdata/dcsequen.h:43,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:42,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/oflist.h:58:2: error: #error Your C++ compiler cannot handle class templates:
/usr/include/dcmtk/ofstd/oflist.h:498:2: error: #error Your C++ Compiler is not capable of compiling this code
In file included from /usr/include/dcmtk/ofstd/ofconsol.h:68,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:39,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofstream.h:102: error: ‘strstream’ does not name a type
/usr/include/dcmtk/ofstd/ofstream.h:103: error: ‘ostrstream’ does not name a type
/usr/include/dcmtk/ofstd/ofstream.h:104: error: ‘istrstream’ does not name a type
In file included from /usr/include/dcmtk/ofstd/ofthread.h:43,
                 from /usr/include/dcmtk/ofstd/ofconsol.h:69,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:39,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘const char& OFString::at(size_t) const’:
/usr/include/dcmtk/ofstd/ofstring.h:336: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘char& OFString::at(size_t)’:
/usr/include/dcmtk/ofstd/ofstring.h:348: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘char OFString::operator[](size_t) const’:
/usr/include/dcmtk/ofstd/ofstring.h:362: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘char& OFString::operator[](size_t)’:
/usr/include/dcmtk/ofstd/ofstring.h:375: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘size_t OFString::size() const’:
/usr/include/dcmtk/ofstd/ofstring.h:404: error: ‘strlen’ was not declared in this scope
In file included from /usr/include/dcmtk/dcmdata/dcerror.h:38,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:41,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofcond.h: In constructor ‘OFCondition::OFCondition(OFConditionString*)’:
/usr/include/dcmtk/ofstd/ofcond.h:321: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofcond.h: In constructor ‘OFCondition::OFCondition(const OFConditionConst&)’:
/usr/include/dcmtk/ofstd/ofcond.h:337: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofcond.h: In copy constructor ‘OFCondition::OFCondition(const OFCondition&)’:
/usr/include/dcmtk/ofstd/ofcond.h:344: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofcond.h: In member function ‘OFCondition& OFCondition::operator=(const OFCondition&)’:
/usr/include/dcmtk/ofstd/ofcond.h:366: error: ‘assert’ was not declared in this scope
In file included from /usr/include/dcmtk/dcmdata/dcpcache.h:39,
                 from /usr/include/dcmtk/dcmdata/dcitem.h:45,
                 from /usr/include/dcmtk/dcmdata/dcsequen.h:43,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:42,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/oflist.h: In member function ‘T& OFIterator<T>::operator*() const’:
/usr/include/dcmtk/ofstd/oflist.h:226: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available
/usr/include/dcmtk/ofstd/oflist.h:226: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
testProgram.cc: In function ‘int main()’:
testProgram.cc:19: error: ‘DCM_PatientName’ was not declared in this scope
[swaroop@schipol dcmtk]$ 
[swaroop@schipol dcmtk]$ g++ -I/usr/include/dcmtk/dcmdata testProgram.cc 
In file included from /usr/include/dcmtk/ofstd/ofconsol.h:68,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:39,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofstream.h:63:22: error: iostream.h: No such file or directory
/usr/include/dcmtk/ofstd/ofstream.h:64:21: error: fstream.h: No such file or directory
/usr/include/dcmtk/ofstd/ofstream.h:76:2: error: #error DCMTK needs stringstream or strstream type
/usr/include/dcmtk/ofstd/ofstream.h:78:21: error: iomanip.h: No such file or directory
In file included from /usr/include/dcmtk/dcmdata/dcpcache.h:39,
                 from /usr/include/dcmtk/dcmdata/dcitem.h:45,
                 from /usr/include/dcmtk/dcmdata/dcsequen.h:43,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:42,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/oflist.h:58:2: error: #error Your C++ compiler cannot handle class templates:
/usr/include/dcmtk/ofstd/oflist.h:498:2: error: #error Your C++ Compiler is not capable of compiling this code
In file included from /usr/include/dcmtk/ofstd/ofconsol.h:68,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:39,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofstream.h:102: error: ‘strstream’ does not name a type
/usr/include/dcmtk/ofstd/ofstream.h:103: error: ‘ostrstream’ does not name a type
/usr/include/dcmtk/ofstd/ofstream.h:104: error: ‘istrstream’ does not name a type
In file included from /usr/include/dcmtk/ofstd/ofthread.h:43,
                 from /usr/include/dcmtk/ofstd/ofconsol.h:69,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:39,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘const char& OFString::at(size_t) const’:
/usr/include/dcmtk/ofstd/ofstring.h:336: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘char& OFString::at(size_t)’:
/usr/include/dcmtk/ofstd/ofstring.h:348: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘char OFString::operator[](size_t) const’:
/usr/include/dcmtk/ofstd/ofstring.h:362: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘char& OFString::operator[](size_t)’:
/usr/include/dcmtk/ofstd/ofstring.h:375: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘size_t OFString::size() const’:
/usr/include/dcmtk/ofstd/ofstring.h:404: error: ‘strlen’ was not declared in this scope
In file included from /usr/include/dcmtk/dcmdata/dcerror.h:38,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:41,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/ofcond.h: In constructor ‘OFCondition::OFCondition(OFConditionString*)’:
/usr/include/dcmtk/ofstd/ofcond.h:321: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofcond.h: In constructor ‘OFCondition::OFCondition(const OFConditionConst&)’:
/usr/include/dcmtk/ofstd/ofcond.h:337: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofcond.h: In copy constructor ‘OFCondition::OFCondition(const OFCondition&)’:
/usr/include/dcmtk/ofstd/ofcond.h:344: error: ‘assert’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofcond.h: In member function ‘OFCondition& OFCondition::operator=(const OFCondition&)’:
/usr/include/dcmtk/ofstd/ofcond.h:366: error: ‘assert’ was not declared in this scope
In file included from /usr/include/dcmtk/dcmdata/dcpcache.h:39,
                 from /usr/include/dcmtk/dcmdata/dcitem.h:45,
                 from /usr/include/dcmtk/dcmdata/dcsequen.h:43,
                 from /usr/include/dcmtk/dcmdata/dcfilefo.h:42,
                 from testProgram.cc:8:
/usr/include/dcmtk/ofstd/oflist.h: In member function ‘T& OFIterator<T>::operator*() const’:
/usr/include/dcmtk/ofstd/oflist.h:226: error: there are no arguments to ‘assert’ that depend on a template parameter, so a declaration of ‘assert’ must be available
/usr/include/dcmtk/ofstd/oflist.h:226: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
testProgram.cc: In function ‘int main()’:
testProgram.cc:19: error: ‘DCM_PatientName’ was not declared in this scope
---
Manohar Kuse
SenoCAD Research
Alkmaar, The Netherlands

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

#6 Post by Michael Onken »

Hi,

trying to include the DCMTK-related include files first.

I compiled a very small test program (test.cc) on my linux system:

Code: Select all


#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
#include <ostream>
using namespace std;

int main()
{
  char uid[100];
  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_PatientName, "Doe^John");
  OFCondition status = fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
  if (status.bad())
  cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;
  return 0;
}
I used for that:
g++ test.cc -I /dcmtk-install/include -L /dcmtk-install/lib -ldcmdata -loflog -lofstd -lpthread -lz -o test
Replace "/dcmtk-install/" with the directory where you have DCMTK installed.

In your application, replace everything before main() with:

Code: Select all

#include "dcmtk/dcmdata/dctk.h" //in dcmdata
#include <ostream>
using namespace std;
and use the same commandline as above (with testProgram instead of test as filenames). Works fine for me.

Michael

swaroopcool21
Posts: 12
Joined: Wed, 2011-03-23, 12:40
Location: Alkmaar, The Netherlands
Contact:

#7 Post by swaroopcool21 »

Dear Sir,

It is still not working.
I have downloaded dcmtk from
http://www.dcmtk.org/download/dcmtk/dcmtk360/

and it was successfully installed.
on my linux pc, i could even find the file `dctk.h'

I tried to compile the program which was suggested by you.

I get following message from the compiler

Code: Select all

In file included from /usr/include/dcmtk/ofstd/ofstring.h:63,
                 from /usr/include/dcmtk/ofstd/ofcond.h:39,
                 from /usr/include/dcmtk/dcmdata/dcerror.h:38,
                 from /usr/include/dcmtk/dcmdata/dcswap.h:39,
                 from /usr/include/dcmtk/dcmdata/dctk.h:41,
                 from test.cc:9:
/usr/include/dcmtk/ofstd/ofstream.h:63:22: error: iostream.h: No such file or directory
/usr/include/dcmtk/ofstd/ofstream.h:64:21: error: fstream.h: No such file or directory
/usr/include/dcmtk/ofstd/ofstream.h:76:2: error: #error DCMTK needs stringstream or strstream type
/usr/include/dcmtk/ofstd/ofstream.h:78:21: error: iomanip.h: No such file or directory
In file included from /usr/include/dcmtk/dcmdata/dchashdi.h:38,
                 from /usr/include/dcmtk/dcmdata/dctk.h:54,
                 from test.cc:9:
/usr/include/dcmtk/ofstd/oflist.h:58:2: error: #error Your C++ compiler cannot handle class templates:
/usr/include/dcmtk/ofstd/oflist.h:498:2: error: #error Your C++ Compiler is not capable of compiling this code
In file included from /usr/include/dcmtk/dcmdata/dctk.h:55,
                 from test.cc:9:
/usr/include/dcmtk/dcmdata/dcdict.h:54:2: error: #error "DCM_DICT_DEFAULT_PATH is not defined via osconfig.h"
In file included from /usr/include/dcmtk/ofstd/ofstring.h:63,
                 from /usr/include/dcmtk/ofstd/ofcond.h:39,
                 from /usr/include/dcmtk/dcmdata/dcerror.h:38,
                 from /usr/include/dcmtk/dcmdata/dcswap.h:39,
                 from /usr/include/dcmtk/dcmdata/dctk.h:41,
                 from test.cc:9:
/usr/include/dcmtk/ofstd/ofstream.h:102: error: ‘strstream’ does not name a type
/usr/include/dcmtk/ofstd/ofstream.h:103: error: ‘ostrstream’ does not name a type
/usr/include/dcmtk/ofstd/ofstream.h:104: error: ‘istrstream’ does not name a type
In file included from /usr/include/dcmtk/ofstd/ofcond.h:39,
                 from /usr/include/dcmtk/dcmdata/dcerror.h:38,
                 from /usr/include/dcmtk/dcmdata/dcswap.h:39,
                 from /usr/include/dcmtk/dcmdata/dctk.h:41,
                 from test.cc:9:
/usr/include/dcmtk/ofstd/ofstring.h: In member function ‘size_t OFString::size() const’:
/usr/include/dcmtk/ofstd/ofstring.h:404: error: ‘strlen’ was not declared in this scope
/usr/include/dcmtk/ofstd/ofstring.h: At global scope:
/usr/include/dcmtk/ofstd/ofstring.h:817: error: expected constructor, destructor, or type conversion before ‘&’ token
/usr/include/dcmtk/ofstd/ofstring.h:825: error: expected constructor, destructor, or type conversion before ‘&’ token
In file included from /usr/include/dcmtk/dcmdata/dctk.h:51,
                 from test.cc:9:
/usr/include/dcmtk/dcmdata/dctagkey.h:88: error: ‘ostream’ is neither function nor member function; cannot be declared friend
/usr/include/dcmtk/dcmdata/dctagkey.h:88: error: expected ‘;’ before ‘&’ token
/usr/include/dcmtk/dcmdata/dctagkey.h:104: error: expected constructor, destructor, or type conversion before ‘&’ token
In file included from /usr/include/dcmtk/dcmdata/dctk.h:53,
                 from test.cc:9:
/usr/include/dcmtk/dcmdata/dcdicent.h:370: error: ‘ostream’ is neither function nor member function; cannot be declared friend
/usr/include/dcmtk/dcmdata/dcdicent.h:370: error: expected ‘;’ before ‘&’ token
/usr/include/dcmtk/dcmdata/dcdicent.h: In member function ‘int DcmDictEntry::privateCreatorMatch(const char*) const’:
/usr/include/dcmtk/dcmdata/dcdicent.h:155: error: ‘strcmp’ was not declared in this scope
/usr/include/dcmtk/dcmdata/dcdicent.h: In member function ‘int DcmDictEntry::contains(const char*) const’:
/usr/include/dcmtk/dcmdata/dcdicent.h:333: error: ‘strcmp’ was not declared in this scope
In file included from /usr/include/dcmtk/dcmdata/dctk.h:54,
                 from test.cc:9:
/usr/include/dcmtk/dcmdata/dchashdi.h: At global scope:
/usr/include/dcmtk/dcmdata/dchashdi.h:257: error: expected ‘;’ before ‘&’ token
In file included from /usr/include/dcmtk/dcmdata/dcobject.h:41,
                 from /usr/include/dcmtk/dcmdata/dctk.h:59,
                 from test.cc:9:
/usr/include/dcmtk/ofstd/ofconsol.h:95: error: expected ‘;’ before ‘&’ token
/usr/include/dcmtk/ofstd/ofconsol.h:105: error: expected ‘;’ before ‘void’
/usr/include/dcmtk/ofstd/ofconsol.h:117: error: expected ‘;’ before ‘&’ token
/usr/include/dcmtk/ofstd/ofconsol.h:133: error: expected ‘;’ before ‘ostream’
/usr/include/dcmtk/ofstd/ofconsol.h:133: error: expected ‘;’ before ‘*’ token
/usr/include/dcmtk/ofstd/ofconsol.h:139: error: expected ‘;’ before ‘&’ token
test.cc:24: error: expected ‘;’ at end of input
test.cc:24: error: expected ‘}’ at end of input
In file included from /usr/include/dcmtk/dcmdata/dcobject.h:41,
                 from /usr/include/dcmtk/dcmdata/dctk.h:59,
                 from test.cc:9:
/usr/include/dcmtk/ofstd/ofconsol.h:110: error: expected unqualified-id at end of input
please help..!
thanks!
---
Manohar Kuse
SenoCAD Research
Alkmaar, The Netherlands

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

#8 Post by Michael Onken »

Hi,

then you do not add the correct inlude path with -I to your compiler. What is your gcc commandline?

Michael

Uli Schlachter
DCMTK Developer
Posts: 120
Joined: Thu, 2009-11-26, 08:15

#9 Post by Uli Schlachter »

Does adding -DHAVE_CONFIG_H to your compiler command line help?

Post Reply

Who is online

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