关于
AIX
服务器上面
c
语言代码的编译问题
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
今天经理分配我任务重新安装和部署开发环境,我三加五除二就部署完成。但是当我编译源代码的时候就出现问题了。我按照之前同事留下的Makefile进行编译。结果出现一堆错误。最后花了一上午的时间才把大部分问题都解决。只有下面的一个问题。我花了一下午的时间才找出问题。
报错信息:
/usr/bin/sh: syntax error at line 1 : `;' unexpected
make: The error code from the last command is 2.
Makefile文件内容如下:
include ${ESWTDIR}/etc/Custom.defines
BLKDIR=${FAPWORKDIR}/src/BUSI/PubApp
ALADIRS=
STATICLIB=${FAPWORKDIR}/lib/libblk.a
SHARELIB=${FAPWORKDIR}/lib/libblk${SHLIBEXT}
BLKOBJS=mon/monsend.o \
mon/monfunc.o \
mon/monsock.o \
mon/monelemfunc.o \
mon/monapp.o \
mon/monviewput.o \
mon/mongettime.o \
rspshm/rspshmfunc.o \
sec/ccb/ccbcryshm.o \
rpt/rptgen.o \
rpt/rptfunc.o \
rpt/rptshmgen.o \
rpt/rptshmfunc.o \
de/elemfunc.o \
pub/pubfunc.o \
pub/dac.o
ARGETS=${STATICLIB
all:
@-cp ${ESWTDIR}/etc/Make.defines ${BLKDIR}/tcplib
@-cp ${ESWTDIR}/include/sysautocf.h ${BLKDIR}/tcplib
@for subdir in ${ALLDIRS}; \
do \
cd $$subdir; \
echo "Makeing $$subdir"; \
${MAKE} ${MAKEOPT} all; \
echo "Done"; \
done
${MAKE} ${MAKEOPT} ${TARGETS}
@-cp ${BLKDIR}/rspshm/rspencfile ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/rspshm/rspshmmng ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/sec/ccb/agt_kinit ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/sec/ccb/agt_kgen ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/sec/ccb/agt_kdump ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/sec/ccb/agt_kload ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/pub/dbloadseq ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/pub/esseq ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/lm/LINKMNG ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/lm/lmshmview ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/simdta/SIMDTA ${FAPWORKDIR}/bin
@-cp ${BLKDIR}/tcpfile/tcpfunc.o ${FAPWORKDIR}/lib
@-cp ${BLKDIR}/tcpfile/tcpfile.o ${FAPWORKDIR}/lib
@for subdir in ${ALADIRS}; \
do \
cd $$subdir; \
echo "Makeing $$subdir"; \
${MAKE} ${MAKEOPT} all; \
echo "Done"; \
done
# @-cp ${BLKDIR}/sd/FILESERVER ${FAPWORKDIR}/bin
# @-cp ${BLKDIR}/sd/UNLOSTFS ${FAPWORKDIR}/bin
# @-cp ${BLKDIR}/sd/libhyp64.a ${FAPWORKDIR}/lib
${STATICLIB}: ${BLKOBJS}
${AR} ${AROPT} $@ ${BLKOBJS}
${RANLIB} $@
${SHARELIB}: ${BLKOBJS}
${LD} ${SHLIBLDOPT} -o $@ ${BLKOBJS}
rm -f ${STATICLIB}; cp ${SHARELIB} ${STATICLIB}
clean:
@for subdir in ${ALLDIRS}; \
do \
cd $$subdir; \
echo "Makeing $$subdir"; \
${MAKE} ${MAKEOPT} clean; \
echo "Done"; \
done
@for subdir in ${ALADIRS}; \
do \
cd $$subdir; \
echo "Makeing $$subdir"; \
${MAKE} ${MAKEOPT} clean; \
echo "Done"; \
done
@- rm -f ${TARGETS}
问题分析及其解决方法:在Makefile里面打日志,一行行的分析,最后发现在红色标记的部分执行完之后就没有继续执行下去,所以立马就分析红线以下的内容,最后发现变量ALADIRS为空,所以编译器就把for subdir in ${ALADIRS};这句话解析成为for subdir in ; 这样语法就错误。
问题总结:当遇到问题的时候首先就是要找到有“;”的地方,因为根据报错信息是有“;”的地方存在问题。但是凭这点很难找到问题所在的位置,所以就必须打印日志,这个是程序员必备的能力。最后我重点要说的是报错信息下面的那句话
make: The error code from the last command is 2.
现在可以理解这句话的意思,就是最后执行的那个命令的下一个命令。也就是最后执行命令的本身是第一个,接下来错误的是第二个。这样结合这两点就能很好的定位。(注这个是在AIX机器上其他机器可能情况不一样)
转载于:https://blog.51cto.com/2922055/1020785