GDCM与c ++的链接错误

时间:2013-03-16 21:41:52

标签: c++ cmake gdcm

我第一次尝试检查我的gdcm安装。我无法构建任何示例文件。我试图单独构建名为ReadAndDumpDICOMDIR.cxx的文件(重命名为main.cpp):

    #include <gdcmReader.h>
#include <gdcmMediaStorage.h>

typedef std::set<gdcm::DataElement> DataElementSet;
typedef DataElementSet::const_iterator ConstIterator;

int main(int argc, char *argv [])
{
  if( argc < 2 ) return 1;
  const char *filename = argv[1];

  gdcm::Reader reader;
  reader.SetFileName( filename);
  if( !reader.Read() )
    {
    std::cerr << "Could not read: " << filename << std::endl;
    return 1;
    }
  std::stringstream strm;

  gdcm::File &file = reader.GetFile();
  gdcm::DataSet &ds = file.GetDataSet();
  gdcm::FileMetaInformation &fmi = file.GetHeader();

  gdcm::MediaStorage ms;
  ms.SetFromFile(file);
  if( ms != gdcm::MediaStorage::MediaStorageDirectoryStorage )
    {
    std::cout << "This file is not a DICOMDIR" << std::endl;
    return 1;
    }

  if (fmi.FindDataElement( gdcm::Tag (0x0002, 0x0002)))
    {   strm.str("");
    fmi.GetDataElement( gdcm::Tag (0x0002, 0x0002) ).GetValue().Print(strm);
    }
  else
    {
    std::cerr << " Media Storage Sop Class UID not present" << std::cout;
    }

  //TODO il faut trimer strm.str() avant la comparaison au cas ou...
  if ("1.2.840.10008.1.3.10"!=strm.str())
    {
    std::cout << "This file is not a DICOMDIR" << std::endl;
    return 1;
    }

  ConstIterator it = ds.GetDES().begin();

  for( ; it != ds.GetDES().end(); ++it)
    {

    if (it->GetTag()==gdcm::Tag (0x0004, 0x1220))
      {

      const gdcm::DataElement &de = (*it);
      // ne pas utiliser GetSequenceOfItems pour extraire les items
      gdcm::SmartPointer<gdcm::SequenceOfItems> sqi =de.GetValueAsSQ();
      unsigned int itemused = 1;
      while (itemused<=sqi->GetNumberOfItems())

        {
        strm.str("");

        if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
          sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);

        //TODO il faut trimer strm.str() avant la comparaison
        while((strm.str()=="PATIENT")||((strm.str()=="PATIENT ")))
          {
          std::cout << strm.str() << std::endl;
          strm.str("");
          if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0010, 0x0010)))
            sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0010, 0x0010)).GetValue().Print(strm);
          std::cout << "PATIENT NAME : " << strm.str() << std::endl;


          //PATIENT ID
          strm.str("");
          if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0010, 0x0020)))
            sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0010, 0x0020)).GetValue().Print(strm);
          std::cout << "PATIENT ID : " << strm.str() << std::endl;

          /*ADD TAG TO READ HERE*/
          std::cout << "=========================== "  << std::endl;
          itemused++;
          strm.str("");
          if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
            sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);

          //TODO il faut trimer strm.str() avant la comparaison
          while((strm.str()=="STUDY")||((strm.str()=="STUDY ")))
            {
            std::cout << "  " << strm.str() << std::endl;
            //UID
            strm.str("");
            if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0020, 0x000d)))
              sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0020, 0x000d)).GetValue().Print(strm);
            std::cout << "      STUDY UID : " << strm.str() << std::endl;

            //STUDY DATE
            strm.str("");
            if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x0020)))
              sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x0020)).GetValue().Print(strm);
            std::cout << "      STUDY DATE : " << strm.str() << std::endl;

            //STUDY DESCRIPTION
            strm.str("");
            if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x1030)))
              sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x1030)).GetValue().Print(strm);
            std::cout << "      STUDY DESCRIPTION : " << strm.str() << std::endl;

            /*ADD TAG TO READ HERE*/
            std::cout << "      " << "=========================== "  << std::endl;

            itemused++;
            strm.str("");
            if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
              sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);

            //TODO il faut trimer strm.str() avant la comparaison
            while((strm.str()=="SERIES")||((strm.str()=="SERIES ")))
              {
              std::cout << "      " << strm.str() << std::endl;
              strm.str("");
              if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0020, 0x000e)))
                sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0020, 0x000e)).GetValue().Print(strm);
              std::cout << "          SERIE UID" << strm.str() << std::endl;

              //SERIE MODALITY
              strm.str("");
              if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x0060)))
                sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x0060)).GetValue().Print(strm);
              std::cout << "          SERIE MODALITY" << strm.str() << std::endl;

              //SERIE DESCRIPTION
              strm.str("");
              if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x103e)))
                sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x103e)).GetValue().Print(strm);
              std::cout << "          SERIE DESCRIPTION" << strm.str() << std::endl;


              /*ADD TAG TO READ HERE*/

              std::cout << "          " << "=========================== "  << std::endl;
              itemused++;
              strm.str("");
              if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
                sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);


              //TODO il faut trimer strm.str() avant la comparaison
              while ((strm.str()=="IMAGE")||((strm.str()=="IMAGE ")))
                // if(tmp=="IMAGE")
                {
                std::cout << "          " << strm.str() << std::endl;


                //UID
                strm.str("");
                if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1511)))
                  sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1511)).GetValue().Print(strm);
                std::cout << "              IMAGE UID : " << strm.str() << std::endl;

                //PATH de l'image
                strm.str("");
                if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1500)))
                  sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1500)).GetValue().Print(strm);
                std::cout << "              IMAGE PATH : " << strm.str() << std::endl;
                /*ADD TAG TO READ HERE*/



                if(itemused < sqi->GetNumberOfItems())
                  {itemused++;
                  }else{break;}

                strm.str("");

                if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
                  sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);

                }
              }
            }
          }
        itemused++;
        }
      }
    }
  return 0;
}

我的CMakeLists.txt是

    cmake_minimum_required(VERSION 2.8) 
PROJECT(JPEGReader) 
find_package(GDCM REQUIRED)
INCLUDE(${GDCM_USE_FILE})
set (reader_src main.cpp) 
add_executable(reader ${reader_src})
target_link_libraries (reader gdcmMEXD gdcmMSFF)

但我得到错误

    Linking CXX executable reader
CMakeFiles/reader.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x75): undefined reference to `gdcm::Reader::SetFileName(char const*)'
main.cpp:(.text+0x84): undefined reference to `gdcm::Reader::Read()'
main.cpp:(.text+0x154): undefined reference to `gdcm::MediaStorage::SetFromFile(gdcm::File const&)'
main.cpp:(.text+0x3b1): undefined reference to `gdcm::DataElement::GetValueAsSQ() const'
main.cpp:(.text+0x45a): undefined reference to `gdcm::SequenceOfItems::GetItem(unsigned long)'
main.cpp:(.text+0x4ad): undefined reference to `gdcm::SequenceOfItems::GetItem(unsigned long)'
main.cpp:(.text+0x5cc): undefined reference to `gdcm::SequenceOfItems::GetItem(unsigned long)'
main.cpp:(.text+0x61b): undefined reference to `gdcm::SequenceOfItems::GetItem(unsigned long)'
main.cpp:(.text+0x742): undefined reference to `gdcm::SequenceOfItems::GetItem(unsigned long)'
CMakeFiles/reader.dir/main.cpp.o:main.cpp:(.text+0x791): more undefined references to `gdcm::SequenceOfItems::GetItem(unsigned long)' follow
CMakeFiles/reader.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x1d8d): undefined reference to `gdcm::Reader::~Reader()'
main.cpp:(.text+0x22c9): undefined reference to `gdcm::Reader::~Reader()'
CMakeFiles/reader.dir/main.cpp.o: In function `gdcm::DataSet::GetDataElement(gdcm::Tag const&) const':
main.cpp:(.text._ZNK4gdcm7DataSet14GetDataElementERKNS_3TagE[gdcm::DataSet::GetDataElement(gdcm::Tag const&) const]+0xb1): undefined reference to `gdcm::DataSet::GetDEEnd() const'
CMakeFiles/reader.dir/main.cpp.o: In function `gdcm::FileMetaInformation::FileMetaInformation()':
main.cpp:(.text._ZN4gdcm19FileMetaInformationC2Ev[_ZN4gdcm19FileMetaInformationC5Ev]+0x50): undefined reference to `gdcm::Preamble::Preamble()'
CMakeFiles/reader.dir/main.cpp.o: In function `gdcm::FileMetaInformation::~FileMetaInformation()':
main.cpp:(.text._ZN4gdcm19FileMetaInformationD2Ev[_ZN4gdcm19FileMetaInformationD5Ev]+0x19): undefined reference to `gdcm::Preamble::~Preamble()'
CMakeFiles/reader.dir/main.cpp.o: In function `gdcm::Reader::Reader()':
main.cpp:(.text._ZN4gdcm6ReaderC2Ev[_ZN4gdcm6ReaderC5Ev]+0x16): undefined reference to `vtable for gdcm::Reader'
collect2: ld returned 1 exit status
make[2]: *** [reader] Error 1
make[1]: *** [CMakeFiles/reader.dir/all] Error 2
make: *** [all] Error 2

我最终知道如何解决这个问题。欢迎任何帮助。另请注意,我无法构建共享库,并且build-with-VTK设置为true,如果这意味着什么。感谢

1 个答案:

答案 0 :(得分:0)

问题解决了。在安装到我的/ usr / local / gcmbin中时,cmake似乎一直在跳过库,即使我按照所有步骤操作。我在/ home / usman目录中创建了一个新文件夹并重复了该过程。现在它链接。谢谢你看看这个问题。至少我现在可以RIP了:)