Как запустить примеры gdcm в Ubuntu? - PullRequest
0 голосов
/ 08 июня 2018

Я пытаюсь запустить этот простой пример в GDCM.Я установил версию библиотеки c ++, и установка работает отлично, но я не могу понять, как скомпилировать и запустить пример.

#include "gdcmReader.h"
#include "gdcmWriter.h"
#include "gdcmAttribute.h"

#include <iostream>

int main(int argc, char *argv[])
{
  if( argc < 3 )
    {
    std::cerr << argv[0] << " input.dcm output.dcm" << std::endl;
    return 1;
    }
  const char *filename = argv[1];
  const char *outfilename = argv[2];

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

  // If we reach here, we know for sure only 1 thing:
  // It is a valid DICOM file (potentially an old ACR-NEMA 1.0/2.0 file)
  // (Maybe, it's NOT a Dicom image -could be a DICOMDIR, a RTSTRUCT, etc-)

  // The output of gdcm::Reader is a gdcm::File
  gdcm::File &file = reader.GetFile();

  // the dataset is the the set of element we are interested in:
  gdcm::DataSet &ds = file.GetDataSet();

  // Contruct a static(*) type for Image Comments :
  gdcm::Attribute<0x0020,0x4000> imagecomments;
  imagecomments.SetValue( "Hello, World !" );

  // Now replace the Image Comments from the dataset with our:
  ds.Replace( imagecomments.GetAsDataElement() );

  // Write the modified DataSet back to disk
  gdcm::Writer writer;
  writer.CheckFileMetaInformationOff(); // Do not attempt to reconstruct the file meta to preserve the file
                                        // as close to the original as possible.
  writer.SetFileName( outfilename );
  writer.SetFile( file );
  if( !writer.Write() )
    {
    std::cerr << "Could not write: " << outfilename << std::endl;
    return 1;
    }

  return 0;
}

/*
 * (*) static type, means that extra DICOM information VR & VM are computed at compilation time.
 * The compiler is deducing those values from the template arguments of the class.
 */

У него есть несколько заголовочных файлов, которые он ищет, а именноgdcmreader, gdcmwriter и я хотим выяснить флаги компилятора, которые будут использоваться для запуска этого файла.
Я делаю g++ a.cpp -lgdcmCommon -lgdcmDICT, но это дает мне ошибку

a.cpp:18:24: fatal error: gdcmReader.h: No such file or directory
compilation terminated.

Можете ли вы помочьменя нет?Я искал везде, но я не могу понять, как запустить этот файл.

Ответы [ 2 ]

0 голосов
/ 11 июня 2018

Вы не рассказали, как вы установили библиотеку gdcm, я предполагаю, что использую apt систему.Существует два типа библиотек: «обычные» и «разработчики».Чтобы иметь возможность скомпилировать собственное программное обеспечение, вам нужно последнее.Так, например, в Ubuntu 16.04 введите apt-get install libgdcm2-dev.Тогда все необходимые заголовки будут установлены в /usr/include/gdcm-2.6.

0 голосов
/ 08 июня 2018

При использовании файлов, которые находятся в разных местах ваших "обычных" файлов, вы должны указать компилятору и компоновщику, как их найти.

В вашем коде есть команда #include <someFile.h>.
Использование <> означает «по другому пути».Компилятор уже знает общие «другие пути», как и «stdio» для общих библиотек.
В случае "не нормально", вы можете указать g ++, где искать заголовки, добавив -Imydir в командную строку (замените 'mydir' на правильный путь)

Длябиблиотеки, статические (.a) или динамические (.so) одинаковые истории.
-Lmydir указывает g ++, где искать библиотеки.

Ваша командная строка может выглядеть как

g++ a.cpp -I/usr/include -L/usr/local/lib -lgdcmCommon -lgdcmDICT
...