【问题标题】:How to run gdcm examples in ubuntu?如何在 ubuntu 中运行 gdcm 示例?
【发布时间】:2018-06-08 18:45:22
【问题描述】:

我正在尝试在 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.

你能帮帮我吗?我到处搜索,但我似乎无法弄清楚如何运行这个文件。

【问题讨论】:

  • #include "myfile.h"#include &lt;myfile.h&gt; 不同。此外,g++ 需要知道 GDCM 库 (.so) 在哪里。
  • 我确实将所有逗号分别更改为 。所有 .a 文件都在 /usr/local/lib
  • 还是不知道怎么用。

标签: c++ compilation dicom gdcm


【解决方案1】:

当使用位于“正常”文件不同位置的文件时,您必须指示编译器和链接器如何找到它们。

您的代码有一个#include &lt;someFile.h&gt; 命令。
&lt;&gt; 用法表示“在其他路径中”。编译器已经知道常见的“其他路径”,就像常见库的“stdio”一样。
在“不正常”的情况下,您可以通过在命令行中添加 -Imydir 来告诉 g++ 在哪里可以找到标头(将 'mydir' 替换为正确的路径)

对于库,静态 (.a) 或动态 (.so) 具有相同的历史记录。
-Lmydir 告诉 g++ 在哪里寻找库。

你的命令行可能看起来像

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

【讨论】:

  • 我也尝试使用该命令,但没有成功。输出保持不变,是的,我正在用目录替换我的目录
  • 查找 GDCM 头文件和库的位置。替换命令行中的路径。
【解决方案2】:

你没有告诉你是如何安装gdcm库的,我假设使用apt系统。有两种类型的库,“普通”库和“开发者”库。为了能够编译您自己的软件,您需要后者。因此,例如在 Ubuntu 16.04 中,键入 apt-get install libgdcm2-dev。然后所有必要的头文件都将安装在/usr/include/gdcm-2.6

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 2015-04-22
    • 2016-05-14
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多