对要编译的.cpp要加入到Makefile.am上面
格式如下:
bin_PROGRAMS = 可执行文件名
***_SOURCES = 所有要参加编译的.cpp文件,文件之间用空格隔开
LIBS = -lpthread -L/usr/local/lib -lpcap –lz //加入库
DEFS += -DNORMAL
DEFS += –DPDEBUG //打开调试信息 定义DPDEBUG
INCLUDES = -I../include //将上级的include路径引进来
#INCLUDES = $(DEPS_CFLAGS)#LDADD = $(DEPS_LIBS)
02-12-12, 00:47
今天我编译esound的时候,没有注意到其依赖于audiofile,以致出错。编译好audiofile后,回来重新编译esound,仍然有以下错误:
(cd .libs && rm -f libesddsp.so && ln -s libesddsp.so.0.2.29 libesddsp.so)
ar cru .libs/libesddsp.a esddsp.o
ranlib .libs/libesddsp.a
creating libesddsp.la
(cd .libs && rm -f libesddsp.la && ln -s ../libesddsp.la libesddsp.la)
gcc -DHAVE_CONFIG_H -I. -I. -I. -DSYSCONFDIR=/"/etc/" -DSERVERDIR=/"/usr/bin/" -g -O2 -c esdcat.c
/bin/sh ./libtool --mode=link gcc -g -O2 -o esdcat esdcat.o libesd.la
gcc -g -O2 -o .libs/esdcat esdcat.o ./.libs/libesd.so
./.libs/libesd.so: undefined reference to `afGetSampleFormat'
./.libs/libesd.so: undefined reference to `afReadFrames'
./.libs/libesd.so: undefined reference to `afGetChannels'
./.libs/libesd.so: undefined reference to `afCloseFile'
./.libs/libesd.so: undefined reference to `afGetRate'
./.libs/libesd.so: undefined reference to `afGetFrameCount'
./.libs/libesd.so: undefined reference to `afOpenFile'
./.libs/libesd.so: undefined reference to `afGetTrackBytes'
collect2: ld returned 1 exit status
make[2]: *** [esdcat] Error 1
make[2]: Leaving directory `/usr/src/esound-0.2.29'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/src/esound-0.2.29'
make: *** [all-recursive-am] Error 2
正无奈的时候,决定删除这个目录(我想make clean也是可以的),重新解包、编译,竟然成功了!请问这个“undefined reference to”何解?
tram
02-12-12, 08:32
是这样的,你安装了audiofile后,esound并不知道,因为它的configure脚本已经运行了,并生成了makefile,所以要make clean+make distclean,有时这样也不管用,有的包提供的make clean和make distclean脚本不能把生成的代码完全删除,最干净的方法就是重新解压。我觉得内核的make mrproper可能是最完善的脚本了,能把生成的东西全给删了。undefined reference就是缺少类型定义,一般是少头文件。