2

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.

Community
  • 1
  • 1
razvanc
  • 930
  • 2
  • 11
  • 18
  • Come on guys, someone has to know something... this isn't really CCfits related, it's more C++... as I can't figure out why even though a function is defined in the header I can't use it in my program... Thanks :) – razvanc Apr 07 '14 at 12:38

3 Answers3

1

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.

Alex Filatov
  • 2,232
  • 3
  • 32
  • 39
  • Well, thanks for the answer but I've since long moved from this and I'm not in need of it anymore so I won't spend any more time trying to figure out what went wrong. That said, hopefully someone else will find this useful – razvanc May 08 '15 at 23:41
1

you just need one thing :

#include <CCfits>

in the head of your code (then you can remove other ccfits includes) The reason is simple. 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

Anthony.

atoy
  • 101
  • 1
  • 3
0

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 ...
Sufian
  • 6,405
  • 16
  • 66
  • 120
  • Well yes, that might be, but I was using (I moved on from this...) the packages that come with Ubuntu: `libccfits-dev` and `libccfits0` so they install in `/usr/lib/x86_64-linux-gnu/libCCfits.*` and `/usr/include/CCfits` respectively, hence the `-L/usr/lib/x86_64-linux-gnu/` in the compilation. But even with this it doesn't work. Now I did realize something, the `/usr/lib...` files are `libCCfits.so.*`. Is it not working maybe because there is no `libCCfirst.so` specifically? I can't recall if the linker also looks at `.so.0*` files... Thanks anyway – razvanc Jun 25 '14 at 11:23