c++ - 如何在 ubuntu 中运行 gdcm 示例?
问题描述
我正在尝试在 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”一样。
在“不正常”的情况下,您可以通过添加到命令行来告诉 g++ 在哪里找到标头-Imydir
(将“mydir”替换为正确的路径)
对于库,静态 (.a) 或动态 (.so) 具有相同的历史记录。
告诉 g++在-Lmydir
哪里寻找库。
您的命令行可能看起来像
g++ a.cpp -I/usr/include -L/usr/local/lib -lgdcmCommon -lgdcmDICT
推荐阅读
- reactjs - 使用 simpleWebRTC 进行存储设置
- usb - C# WPF 在外部 USB 相机按钮上捕获图像
- dart - 使用 Dartson 进行 Json 序列化
- java - 如何在同一个类中创建两个不同的构造函数 - Android
- python - 调试/逐步了解导入模块的工作
- telegram - 电报聊天ID可以做什么?
- java - 为什么我的程序不读取使用同一程序创建的文件?
- typescript - TS - 无法从子级调用 super() 内的公共方法
- git - 删除我的 repo 访问权限后,我可以在 git/sourcetree 中“放弃更改”(恢复文件删除)吗?
- javascript - recompose 库中的 Compose 方法