I am receiving an undefined reference error for every function used from the cfitsio library when compiling my code. Below is the relevant chunk of the make null command's output (Note that -L/usr/lib/ -lcfitsio is in the first line):
gcc -g -I../mdl/null -DCHABRIER -DCHANGESOFT -DDENSITYU -DDENSITYUNOTP -DDIFFUSION -DDODVDS -DDTADJUST -DEPSACCH -DPARTICLESPLIT -DPROMOTE -DGASOLINE -DJEANSSOFT -DNSMOOTHINNER -DRTFORCE -DSETTRAPFPE -DSTARFORM -DTHERMALCOND -DTOPHATFEEDBACK -DTWOPHASE -DVSIGVISC -DWENDLAND -DRADIATION -DRADIATIONLUM -DDDSIMPLE -DR2PPBMAX -DCOOLING_METAL -L/usr/lib/ -lcfitsio -I/usr/include/fitsio.h -o gasoline.dfTest main.o master.o param.o outtype.o pkd.o pst.o grav.o ewald.o walk.o eccanom.o hypanom.o fdl.o htable.o smooth.o smoothfcn.o collision.o qqsmooth.o cooling_metal.o cosmo.o romberg.o starform.o feedback.o millerscalo.o supernova.o supernovaia.o startime.o stiff.o runge.o dumpframe.o dffuncs.o dumpvoxel.o rotbar.o special.o ssio.o treezip.o log.o radiation.o erf.o v_sqrt1.o ../mdl/null/mdl.o -lm
dumpframe.o: In function `fitsError':
/.../dumpframe.c:2156: undefined reference to `ffrprt'
dumpframe.o: In function `dfFinishFrame':
/.../dumpframe.c:2175: undefined reference to `ffinit'
/.../dumpframe.c:2176: undefined reference to `ffcrim'
/.../dumpframe.c:2197: undefined reference to `ffppr'
/.../dumpframe.c:2198: undefined reference to `ffclos'
collect2: error: ld returned 1 exit status
Makefile:539: recipe for target 'gasoline.dfTest' failed
make[1]: *** [gasoline.dfTest] Error 1
make[1]: Leaving directory '/home/grondjj/Code/gasoline'
Makefile:457: recipe for target 'null' failed
make: *** [null] Error 2gcc -g -I../mdl/null -DCHABRIER -DCHANGESOFT -DDENSITYU -DDENSITYUNOTP -DDIFFUSION -DDODVDS -DDTADJUST -DEPSACCH -DPARTICLESPLIT -DPROMOTE -DGASOLINE -DJEANSSOFT -DNSMOOTHINNER -DRTFORCE -DSETTRAPFPE -DSTARFORM -DTHERMALCOND -DTOPHATFEEDBACK -DTWOPHASE -DVSIGVISC -DWENDLAND -DRADIATION -DRADIATIONLUM -DDDSIMPLE -DR2PPBMAX -DCOOLING_METAL -L/usr/lib/ -lcfitsio -I/usr/include/fitsio.h -o gasoline.dfTest main.o master.o param.o outtype.o pkd.o pst.o grav.o ewald.o walk.o eccanom.o hypanom.o fdl.o htable.o smooth.o smoothfcn.o collision.o qqsmooth.o cooling_metal.o cosmo.o romberg.o starform.o feedback.o millerscalo.o supernova.o supernovaia.o startime.o stiff.o runge.o dumpframe.o dffuncs.o dumpvoxel.o rotbar.o special.o ssio.o treezip.o log.o radiation.o erf.o v_sqrt1.o ../mdl/null/mdl.o -lm
dumpframe.o: In function `fitsError':
/.../dumpframe.c:2156: undefined reference to `ffrprt'
dumpframe.o: In function `dfFinishFrame':
/.../dumpframe.c:2175: undefined reference to `ffinit'
/.../dumpframe.c:2176: undefined reference to `ffcrim'
/.../dumpframe.c:2197: undefined reference to `ffppr'
/.../dumpframe.c:2198: undefined reference to `ffclos'
collect2: error: ld returned 1 exit status
Makefile:539: recipe for target 'gasoline.dfTest' failed
make[1]: *** [gasoline.dfTest] Error 1
make[1]: Leaving directory '/home/grondjj/Code/gasoline'
Makefile:457: recipe for target 'null' failed
make: *** [null] Error 2
Here are the relevant lines from the Makefile for make null
FITS_LIB = -L/usr/lib/ -lcfitsio
BASE_LD_FLAGS = $(PNG_LIB) $(GSL_LIB) $(FITS_LIB)
NULL_LD_FLAGS = $(BASE_LD_FLAGS)
null:
cd $(NULL_MDL); make "CC=$(CC)" "CFLAGS=$(NULL_CFLAGS)"
make $(EXE) "CFLAGS=$(NULL_CFLAGS)" "LD_FLAGS=$(NULL_LD_FLAGS)"\
"MDL=$(NULL_MDL)" "XOBJ=$(NULL_XOBJ)" "LIBMDL=$(NULL_LIBMDL)"
In dumpframe.c I include the cfitsio header fitsio.h along with the other inlcudes at the top of the file:
#ifndef GSS_DUMPFRAME
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include "fitsio.h"
The library was installed from source code. The source resides in /usr/local/src/cfitsio/, it was then installed via the following commands:
$ ./configure --prefix=/usr
$ make shared
$ make install
$ make clean
Which results in the libraries (libcfitsio.a, libcfitsio.so, libcfitsio.so.5, libcfitsio.so.5.3.39) being installed in /usr/lib/ and the auxiliary files (longnam.h, fitsio.h, fitsio2.h, drvrsmem.h) being installed in /usr/include/.
I am not sure what causes this, as the compiler does not complain about missing libraries or a missing fitsio.h header file.