DICOM @ OFFIS

Discussion Forum for OFFIS DICOM Tools - For registration, send email with desired user name to the OFFIS DICOM team
It is currently Mon, 2018-10-22, 04:41

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat, 2011-03-26, 12:25 
Offline

Joined: Wed, 2011-03-23, 12:40
Posts: 12
Location: Alkmaar, The Netherlands
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:
#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


Top
 Profile  
 
 Post subject:
PostPosted: Mon, 2011-03-28, 07:40 
Offline
DCMTK Developer

Joined: Fri, 2004-11-05, 13:47
Posts: 1693
Location: Oldenburg, Germany
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:
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon, 2011-03-28, 10:57 
Offline

Joined: Wed, 2011-03-23, 12:40
Posts: 12
Location: Alkmaar, The Netherlands
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed, 2011-03-30, 11:41 
Offline

Joined: Wed, 2011-03-23, 12:40
Posts: 12
Location: Alkmaar, The Netherlands
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed, 2011-03-30, 11:47 
Offline

Joined: Wed, 2011-03-23, 12:40
Posts: 12
Location: Alkmaar, The Netherlands
Following is my program --

Code:
#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:
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:

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed, 2011-03-30, 17:03 
Offline
DCMTK Developer

Joined: Fri, 2004-11-05, 13:47
Posts: 1693
Location: Oldenburg, Germany
Hi,

trying to include the DCMTK-related include files first.

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

#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:
Quote:
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:
#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


Top
 Profile  
 
 Post subject:
PostPosted: Thu, 2011-03-31, 12:28 
Offline

Joined: Wed, 2011-03-23, 12:40
Posts: 12
Location: Alkmaar, The Netherlands
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:
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri, 2011-04-01, 09:18 
Offline
DCMTK Developer

Joined: Fri, 2004-11-05, 13:47
Posts: 1693
Location: Oldenburg, Germany
Hi,

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

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Fri, 2011-04-01, 10:00 
Offline
DCMTK Developer

Joined: Thu, 2009-11-26, 08:15
Posts: 120
Does adding -DHAVE_CONFIG_H to your compiler command line help?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group