简体   繁体   English

c++ 使用 ccfits 读取 fits 文件

[英]c++ reading fits file using ccfits

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 .我正在尝试按照http://heasarc.gsfc.nasa.gov/fitsio/CCfits/html/readimage.html中的示例使用CCfits读取 C++ 中的*.fits文件。

#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:虽然我查看了/usr/include/CCfits/PHDU.h并且它有这个:

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

Is it possible that libCCfits wasn't compiled right? libCCfits是否可能未正确编译?

(this is somewhat related to CCfits library demo code not working , but since no one really expanded on that... I'm left with nothing). (这在某种程度上与CCfits library demo code not working相关,但由于没有人真正对此进行扩展......我一无所有)。 This is driving me crazy, I'm thinking I'm missing something really obvious.这让我发疯,我想我错过了一些非常明显的东西。

Thanks.谢谢。

you just need one thing:你只需要一件事:

#include <CCfits>

in the head of your code (then you can remove other ccfits includes) The reason is simple.在你的代码头部(然后你可以删除其他 ccfits 包含)原因很简单。 The code for the PHDU::read() methods is not a part of the shared library, but is "included" in "include" files (PHDUT.h to be precise)... so they will be compiled into your own program PHDU::read() 方法的代码不是共享库的一部分,而是“包含”在“include”文件中(准确地说是 PHDUT.h)...因此它们将被编译到您自己的程序中

Anthony.安东尼。

The standard configure and make , make install loop of the CCfits installation puts the libraries into a /.libs folder of the code. CCfits安装的标准configuremakemake install循环将库放入代码的/.libs文件夹中。 Unless you're using the libtools, the -L compiler/linker switch needs to look down into this to find the library: 除非您使用libtools,否则-L compiler/linker开关需要仔细检查才能找到该库:

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

If there is no libCCfits.so , this is an error in the Linux distribution you're using. 如果没有libCCfits.so ,这是您使用的Linux发行版中的错误。 (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. (我在较旧的Fedora发行版上遇到了与其他库相等的问题。)解决该问题的最简单方法是,将libCCfits.solibCCfits.so.0的符号链接添加到libCCfits.so.0.0.0 ,假设后者存在在..../.libs文件夹中。 The alternative is to compile the source package of CCfits-2.4.tar.gz yourself via 另一种方法是通过自己编译CCfits-2.4.tar.gz的源包

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. 点的位置取决于您的喜好以及基础cfitsio的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM