Not able to use this C++ library in D

rnd r_narang at yahoo.com
Thu Jun 6 04:06:33 UTC 2019


I am trying to use C++ DCMTK library ( https://dcmtk.org/ ) 
functions in D.
A relevant reference page is 
https://support.dcmtk.org/docs/classDcmFileFormat.html#details


Following is C++ code modified from 
https://stackoverflow.com/questions/5052148/how-to-use-dcmtk-in-qt

#include "dcmtk/dcmdata/dctk.h"
#include <iostream>
using namespace std;

int main() {
    DcmFileFormat fileformat;
    OFCondition status = fileformat.loadFile("test.dcm");
    if (status.good())   {
		cout << "File loaded" << endl;
    }else{
       cerr << "Error: cannot read DICOM file (" << status.text() 
<< ")" << endl;
    }
    return 0;
}


I have tried to do the same in D with following code:

import std.stdio;
extern (C++) void loadFile(FILE *infile);
extern (C++) class DcmFileFormat;
extern (C++) class OFCondition;

void main(){
    DcmFileFormat fileformat;
    OFCondition status = fileformat.loadFile("test.dcm");
    if (status.good())   {
		writeln("File loaded");
    }else{
       writeln("Error: cannot read DICOM file (", status.text(), 
")");
    }
}

However, I am getting following errors:

$ dmd dcmtk_eg.d
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for loadFile
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for loadFile
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for opDot
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for opDispatch
dcmtk_eg.d(10): Error: function 
dcmtk_eg.loadFile(shared(_IO_FILE)* infile) is not callable using 
argument types (DcmFileFormat, string)
dcmtk_eg.d(10):        cannot pass argument fileformat of type 
dcmtk_eg.DcmFileFormat to parameter shared(_IO_FILE)* infile
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for opDot
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for opDispatch
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for mod
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good


Where is the problem and how can it be solved? Thanks for your 
help.




More information about the Digitalmars-d-learn mailing list