sheisc / ucc162.3

A lightweight open-source C compiler for research and education.
382 stars 139 forks source link

第一次执行make -s test报错及其解决办法,mv: cannot stat '/ucl': No such file or directory #13

Open oxygen236 opened 1 year ago

oxygen236 commented 1 year ago

第一次执行make -s test报错及其解决办法,mv: cannot stat '/ucl': No such file or directory

在书(C 编译器剖析,邹昌伟)的第 23 页中第一次执行make -s test时,报错内容如下:

[oxygen@****** ucc]$ make -s test
(exprchk.c,314):(output.c,70):warning:Too many arguments
(exprchk.c,314):(output.c,86):warning:Too many arguments
mv: cannot stat '/ucl': No such file or directory
make[1]: *** [Makefile:21: test] Error 1
make: *** [Makefile:25: test] Error 2

问题原因:多级 makefile 及参数传递问题,ucc/Makefile 文件中的变量 $(UCCDIR) 没有传递到 ucc/ucl/Makefile 中,导致报错。 解决办法:将 ucc/Makefile 文件的UCCDIR定义前加 export

正确的 ucc/Makefile 文件如下:

#UCCDIR = /home/iron/bin
cur_mkfile := $(abspath $(lastword $(MAKEFILE_LIST)))
export UCCDIR = $(patsubst %/, %, $(dir $(cur_mkfile)))/bin

修改后重新执行,结果如下

[oxygen@****** ucc]$ make -s test
(exprchk.c,314):(output.c,70):warning:Too many arguments
(exprchk.c,314):(output.c,86):warning:Too many arguments
(exprchk.c,314):(output.c,70):warning:Too many arguments
(exprchk.c,314):(output.c,86):warning:Too many arguments

可能对你有帮助的 makefile 相关代码:

1.打印当前Makefile的路径:

$(warning Makefile path: $(CURDIR)/$(lastword $(MAKEFILE_LIST)))

2.在控制台输出变量 $(UCCDIR)/ucl 的值

$(info $(UCCDIR)/ucl)

希望能帮助到有需要的人!