如何在 ubuntu 中运行 gdcm 示例?
How to run gdcm examples in ubuntu?
我正在尝试在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 <someFile.h>
命令。<>
用法的意思是"在其他路径中"。编译器已经知道公共库的"stdio"等常见的"其他路径"。
在"不正常"的情况下,您可以通过在命令行中添加-Imydir
来告诉 g++ 在哪里可以找到标头(将"mydir"替换为正确的路径(
对于库,静态 (.a( 或动态 (.so( 具有相同的历史记录。-Lmydir
告诉 g++ 在哪里查找库。
您的命令行可能如下所示
g++ a.cpp -I/usr/include -L/usr/local/lib -lgdcmCommon -lgdcmDICT
你没有告诉你你是如何安装 gdcm 库的,我假设使用apt
系统。有两种类型的库,"普通"和"开发人员"库。为了能够编译自己的软件,您需要后者。因此,例如在 Ubuntu 16.04 中,键入apt-get install libgdcm2-dev
.然后所有必要的标头都将安装在/usr/include/gdcm-2.6
中。
相关文章:
- 激励'inline'说明符的真实世界示例?
- 为什么示例代码访问IUnknown中已删除的内存
- 以下示例中如何避免代码复制?C++/库达
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 示例C++项目编译中的警告
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 为什么理解这个递归示例如此难以转化为直觉?
- Eventloop 卡住:NAO C++ SDK OnFaceDetection 示例
- 如何替换此示例代码片段中已弃用的handler_type_t或 boost::asio::handler_type?
- 适用于 WebView2 旧版本的示例应用程序
- 即使直接从官方示例中复制,也找不到未知类型名称QML_ELEMENT和 QML 模块
- 将数组/向量发送到 c++ 脚本的 cython 示例
- 了解提升执行器示例
- 请求最简单的 OpenMP 目标 GPU 示例
- 两种模板示例有什么区别?
- 有人可以在下面的示例 C++ 程序中解释字符数组 KCHAR1 的奇怪行为吗?
- Distirbute Candy - 查找问题的最小可重现示例
- 如何在 ubuntu 中运行 gdcm 示例?