c++ reading fits file using ccfits

与世无争的帅哥 提交于 2019-12-11 03:00:07

问题


So... can anyone see what I'm doing wrong here?!? I'm trying to read a *.fits file in C++ using CCfits following their example at http://heasarc.gsfc.nasa.gov/fitsio/CCfits/html/readimage.html.

#include <iostream>
#include <valarray>
#include <CCfits/CCfits.h>
#include <CCfits/PHDU.h>

namespace fit = CCfits;

int main(int argc, char * argv[]) {
    fit::FITS inFile(
        "../data/example/example.fits",
        fit::Read,
        true
    );

    fit::PHDU & phdu = inFile.pHDU();

    std::valarray<unsigned int> fitsImage;
    phdu.read(fitsImage);

    return 0;
}

I get the following error:

undefined reference to `void CCfits::PHDU::read<unsigned int>(std::valarray<unsigned int>&)'
collect2: error: ld returned 1 exit status

I'm linking with this:

g++ test.cpp -o test -L/usr/lib/x86_64-linux-gnu/ -std=c++11 -lCCfits -lcfitsio

Although I looked at /usr/include/CCfits/PHDU.h and it has this:

template<typename S>
void read(std::valarray<S>& image);

Is it possible that libCCfits wasn't compiled right?

(this is somewhat related to CCfits library demo code not working, but since no one really expanded on that... I'm left with nothing). This is driving me crazy, I'm thinking I'm missing something really obvious.

Thanks.


回答1:


The standard configure and make, make install loop of the CCfits installation puts the libraries into a /.libs folder of the code. Unless you're using the libtools, the -L compiler/linker switch needs to look down into this to find the library:

g++ ...  -Lblabla/CCfits/CCfits/.libs ...



回答2:


If there is no libCCfits.so, this is an error in the Linux distribution you're using. (I have encountered equivalenet problems with other libraries on older Fedora distributions.) The simplest way to fix it is to add a symbolic link from libCCfits.so and libCCfits.so.0 to libCCfits.so.0.0.0, assuming the latter exists in the ..../.libs folder. The alternative is to compile the source package of CCfits-2.4.tar.gz yourself via

tar -xzf CCfits-2.4.tar.gz

cd CCfits

./configure --prefix=.... --with-cfitsio-include=..../cfitsio/cfitsio --enable-static LDFLAGS="-L..../cfitsio/cfitsio"

where the dots depend on your preferences and on the location of the underlying cfitsio.



来源:https://stackoverflow.com/questions/22820019/c-reading-fits-file-using-ccfits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!