【发布时间】:2016-07-18 20:28:15
【问题描述】:
我在编译我的代码时收到 cfitsio 库中使用的每个函数的未定义引用错误。下面是 make null 命令输出的相关部分(注意 -L/usr/lib/ -lcfitsio 在第一行):
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
以下是 Makefile 中 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)"
在 dumpframe.c 中,我在文件顶部包含 cfitsio 标头 fitsio.h 以及其他包含:
#ifndef GSS_DUMPFRAME
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include "fitsio.h"
该库是从源代码安装的。源代码位于 /usr/local/src/cfitsio/,然后通过以下命令安装:
$ ./configure --prefix=/usr
$ make shared
$ make install
$ make clean
这会导致库(libcfitsio.a、libcfitsio.so、libcfitsio.so.5、libcfitsio.so .5.3.39) 安装在 /usr/lib/ 和辅助文件 (longnam.h、fitsio.h , fitsio2.h, drvrsmem.h) 安装在 /usr/include/ 中。
我不确定是什么原因造成的,因为编译器不会抱怨缺少库或缺少 fitsio.h 头文件。
【问题讨论】:
标签: c gcc makefile libraries undefined-reference