CCfits库演示代码不起作用 [英] CCfits library demo code not working
问题描述
我是C ++的新手。最终,我试图翻译python的一些代码,以便对一些超新星的模拟进行分析。但是,为了做到这一点,我必须能够将.fits文件作为数组导入到我的C ++代码中。我下载了cfitsio和ccfits库,并且它们似乎已经正确安装,因为包含 #include
#include #include< iostream>
#include< cmath>
#include< memory>
使用命名空间CCfits;
int readimage()
{
std :: auto_ptr< FITS> pInfile(新FITS(Supernova45F.fits,Read,true));
PHDU&图像= pInfile-> pHDU();
std :: valarray< unsigned long>内容;
//读取图像中的所有用户指定,坐标和校验和键
image.readAllKeys();
image.read(contents);
//这不会打印数据,只是标题信息。
std :: cout<<图像<<的std :: ENDL;
long ax1(image.axis(0));
long ax2(image.axis(1));
for(long j = 0; j {
std :: ostream_iterator< short> C(标准:: COUT, \t);
std :: copy(& contents [j * ax1],& contents [(j + 1)* ax1-1],c);
std :: cout<< \\\
;
}
std :: cout<<的std :: ENDL;
返回0;
}
int main(){
return 0;
}
我正在使用以下命令进行编译:
g ++ Sobelattempt.cc -o Sobel -I / home / Sam / CCfits -I / home / Sam / cfitsio
我得到以下错误:
/ tmp /ccS0m6h4.o:在函数`readimage()'中:
Sobelattempt.cc:(.text+0x69):对CCfits :: FITS :: FITS(std :: basic_string< char,std :: char_traits<炭>中的std ::分配器<炭>>常量&安培;, CCfits :: RWmode,布尔,性病::矢量<标准:: basic_string的<炭,性病:: char_traits<炭>中的std ::分配器<炭> ;>,std :: allocator< std :: basic_string< char,std :: char_traits< char>,std :: allocator< char>>> const&)'
Sobelattempt.cc :( ().text + 0x15e):未定义的引用'CCfits :: FITS :: pHDU()'
Sobelattempt.cc:(.text+0x17d):未定义的引用'CCfits :: HDU :: readAllKeys()'
/tmp/ccS0m6h4.o:在函数`std :: auto_ptr< CCfits :: FITS> ::〜auto_ptr()'中:
Sobelattempt.cc:(.text._ZNSt8auto_ptrIN6CCfits4FITSEED2Ev[_ZNSt8auto_ptrIN6CCfits4FITSEED5Ev]+0x1d):未定义的引用`CCfits :: FITS ::〜FITS()'
/tmp/ccS0m6h4.o:在函数`void CCfits: :PHDU :: read< unsigned long>(std :: valarray< unsigned long&; long,long,unsigned long *)':
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long>&; long,long,unsigned long *)] + 0x73):未定义对`typeinfo for CCfits :: PHDU'的引用
Sobelattempt.cc :( .text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_ [void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long&; long,long,unsigned long *)] + 0x12f):未定义的typeinfo CCfits :: PHDU'
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long>&; long,long,unsigned long * )] + 0x20d):未定义参考`所属类别为CCfits :: PHDU
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU ::读取<无符号长>(标准::的valarray<无符号长>&安培;,long,long,unsigned long *)] + 0x2ec):未定义的引用'typeinfo for CCfits :: PHDU'
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long>&; long,long,unsigned long *)] + 0x3b5):未定义的引用'CCfits :: ULBASE'
Sobelattempt.cc :( .text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_ [ void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long>; long,long,unsigned long *)] + 0x435):未定义引用'typeinfo for CCfits :: PHDU'
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long>&; long,long,unsigned long *)] + 0x4 D1):未定义参考`所属类别为CCfits :: PHDU
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU ::读取<无符号长>(标准::的valarray<无符号长>&安培;,long,long,unsigned long *)] + 0x59d):对CCfits :: USBASE的未定义引用
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU :: read< unsigned long> (std :: valarray< unsigned long>&; long,long,unsigned long *)] + 0x61d):未定义的引用'typeinfo for CCfits :: PHDU'
Sobelattempt.cc :( .text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_ [ void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long>&; long,long,unsigned long *)] + 0x6b9):未定义引用'typeinfo for CCfits :: PHDU'
Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits :: PHDU :: read< unsigned long>(std :: valarray< unsigned long&; long,long,unsigned long *)] + 0x77f) :未定义的引用`CCfits :: FitsFatal :: FitsFatal(std :: basic_string< char,std :: char_traits< char> ;, std :: allocator< char> > )'
/tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUImEE[typeinfo for CCfits :: PrimaryHDU< unsigned long>] + 0x10):未定义的引用'typeinfo for CCfits :: PHDU'
/tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIsEE[typeinfo for CCfits :: PrimaryHDU< short> + 0x10):未定义的引用'typeinfo for CCfits :: PHDU'
/tmp/ccS0m6h4.o: (.rodata._ZTIN6CCfits10PrimaryHDUItEE [所属类别为CCfits :: PrimaryHDU<无符号短>] + 0×10):未定义参考`所属类别为CCfits :: PHDU
/tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIiEE[typeinfo对于CCfits :: PrimaryHDU< int>] + 0x10):未定义的对'CCinfo :: PHDU'的typeinfo引用
/tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIjEE[typeinfo for CCfits :: PrimaryHDU< unsigned int> ;] + 0x10):未定义的`typeinfo for CCfits :: PHDU'引用
/tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIhEE[typeinfo for CCfits :: PrimaryHDU< unsigned char>] + 0x10):more undefined ref对于CCfits :: PHDU的`typeinfo'参数跟随
collect2:ld返回1退出状态
解决方案链接到CCfits库的两个链接器选项是-lCCfits -lcfitsio。另外,如果LD_LIBRARY_PATH不包含具有这两个库的目录,则可能需要-L ...标志
。I'm new to C++. Ultimately, I'm trying to translate some code from python in order to perform analysis on some simulations of supernovae. However, in order to do this, I have to be able to import .fits files into my C++ code as an array. I downloaded the cfitsio and ccfits libraries, and they appear to be installed correctly given that a simple code consisting of an
#include <CCfits>
and an int main with a print statement in it compiles and runs. However, taking the demo code from NASA (http://heasarc.gsfc.nasa.gov/fitsio/CCfits/html/readimage.html) with the name changed to the .fits file I wish to open (which is in my home directory) to import a .fits file using these libraries doesn't compile. The precise code I'm using (Sobelattempt.cc) is:#include <CCfits> #include <iostream> #include <cmath> #include <memory> using namespace CCfits; int readimage() { std::auto_ptr<FITS> pInfile(new FITS("Supernova45F.fits",Read,true)); PHDU& image=pInfile->pHDU(); std::valarray<unsigned long> contents; // read all user-specifed, coordinate, and checksum keys in the image image.readAllKeys(); image.read(contents); // this doesn't print the data, just header info. std::cout << image << std::endl; long ax1(image.axis(0)); long ax2(image.axis(1)); for (long j = 0; j < ax2; j+=10) { std::ostream_iterator<short> c(std::cout,"\t"); std::copy(&contents[j*ax1],&contents[(j+1)*ax1-1],c); std::cout << '\n'; } std::cout << std::endl; return 0; } int main(){ return 0; }
I'm compiling using the command:
g++ Sobelattempt.cc -o Sobel -I/home/Sam/CCfits -I/home/Sam/cfitsio
And I get the errors:
/tmp/ccS0m6h4.o: In function `readimage()': Sobelattempt.cc:(.text+0x69): undefined reference to `CCfits::FITS::FITS(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CCfits::RWmode, bool, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)' Sobelattempt.cc:(.text+0x15e): undefined reference to `CCfits::FITS::pHDU()' Sobelattempt.cc:(.text+0x17d): undefined reference to `CCfits::HDU::readAllKeys()' /tmp/ccS0m6h4.o: In function `std::auto_ptr<CCfits::FITS>::~auto_ptr()': Sobelattempt.cc:(.text._ZNSt8auto_ptrIN6CCfits4FITSEED2Ev[_ZNSt8auto_ptrIN6CCfits4FITSEED5Ev]+0x1d): undefined reference to `CCfits::FITS::~FITS()' /tmp/ccS0m6h4.o: In function `void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)': Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x73): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x12f): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x20d): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x2ec): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x3b5): undefined reference to `CCfits::ULBASE' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x435): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x4d1): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x59d): undefined reference to `CCfits::USBASE' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x61d): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x6b9): undefined reference to `typeinfo for CCfits::PHDU' Sobelattempt.cc:(.text._ZN6CCfits4PHDU4readImEEvRSt8valarrayIT_EllPS3_[void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&, long, long, unsigned long*)]+0x77f): undefined reference to `CCfits::FitsFatal::FitsFatal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUImEE[typeinfo for CCfits::PrimaryHDU<unsigned long>]+0x10): undefined reference to `typeinfo for CCfits::PHDU' /tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIsEE[typeinfo for CCfits::PrimaryHDU<short>]+0x10): undefined reference to `typeinfo for CCfits::PHDU' /tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUItEE[typeinfo for CCfits::PrimaryHDU<unsigned short>]+0x10): undefined reference to `typeinfo for CCfits::PHDU' /tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIiEE[typeinfo for CCfits::PrimaryHDU<int>]+0x10): undefined reference to `typeinfo for CCfits::PHDU' /tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIjEE[typeinfo for CCfits::PrimaryHDU<unsigned int>]+0x10): undefined reference to `typeinfo for CCfits::PHDU' /tmp/ccS0m6h4.o:(.rodata._ZTIN6CCfits10PrimaryHDUIhEE[typeinfo for CCfits::PrimaryHDU<unsigned char>]+0x10): more undefined references to `typeinfo for CCfits::PHDU' follow collect2: ld returned 1 exit status
解决方案The two linker options to link to the CCfits library are -lCCfits -lcfitsio . In addition, the -L... flag may be needed if the LD_LIBRARY_PATH does not cover the directory with these two libraries.
这篇关于CCfits库演示代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!