我正在尝试用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.
你能帮帮我吗?我到处都找过了,但我似乎想不出怎么运行这个文件。
发布于 2018-06-09 03:12:11
当使用位于“普通”文件的不同位置的文件时,您必须指示编译器和链接器如何找到它们。
您的代码有一个#include <someFile.h>
命令。
<>
的用法表示“在其他路径中”。对于通用库,编译器已经知道"stdio“的通用”其他路径“。
在“不正常”的情况下,你可以通过在命令行中添加-Imydir
来告诉g++在哪里找到头文件(用正确的路径替换'mydir‘)
对于库,静态(.a)或动态(.so)具有相同的历史。
-Lmydir
告诉g++在哪里查找库。
您的命令行可能如下所示
g++ a.cpp -I/usr/include -L/usr/local/lib -lgdcmCommon -lgdcmDICT
发布于 2018-06-11 15:47:53
你没有说你是如何安装gdcm库的,我假设你使用的是apt
系统。有两种类型的库,“普通”和“开发人员”的。为了能够编译您自己的软件,您需要后者。因此,例如在Ubuntu16.04中,输入apt-get install libgdcm2-dev
。然后所有必要的标头都将安装在/usr/include/gdcm-2.6
中。
https://stackoverflow.com/questions/50766735
复制相似问题