Windows下MinGW64执行Go项目Makefile报错:missing separator
解决MinGW64下Go项目Makefile报错"missing separator"的问题
问题重现
在Windows的MinGW64环境中执行Go项目的Makefile时,持续出现如下报错:
Makefile:5: *** missing separator.
原Makefile内容:
BINARY_NAME=celeritasApp.exe ## build: builds all binaries build: @go mod vendor @go build -o tmp/${BINARY_NAME} . @echo Celeritas built! run: build @echo Staring Celeritas... @. mp\${BINARY_NAME} & @echo Celeritas started! clean: @echo Cleaning... @go clean @del .\tmp\${BINARY_NAME} @echo Cleaned! test: @echo Testing... @go test ./... @echo Done! start: run stop: @echo "Starting the front end..." @taskkill /IM ${BINARY_NAME} /F @echo Stopped Celeritas restart: stop start
使用的make版本:
xxxx@xxxxx MSYS /c/dev/my/go_apps/myapp $ make --version GNU Make 4.3 Built for x86_64-pc-msys Copyright (C) 1988-2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
报错原因分析
该报错的核心原因是Makefile对缩进格式有严格要求:所有目标下的命令行必须使用Tab键缩进,不能用空格或者Tab+空格混合;同时原Makefile还存在两处细节错误:
build、run等目标下的命令用了空格缩进,而非Tabrun目标中的. mp\${BINARY_NAME}是拼写错误(Tab误替换了/),实际应为./tmp/${BINARY_NAME}start目标下存在无意义的空行,可能触发格式校验问题
修复后的Makefile
BINARY_NAME=celeritasApp.exe ## build: builds all binaries build: @go mod vendor @go build -o tmp/${BINARY_NAME} . @echo Celeritas built! run: build @echo Starting Celeritas... @./tmp/${BINARY_NAME} & @echo Celeritas started! clean: @echo Cleaning... @go clean @del .\tmp\${BINARY_NAME} @echo Cleaned! test: @echo Testing... @go test ./... @echo Done! start: run stop: @echo Stopping Celeritas... @taskkill /IM ${BINARY_NAME} /F @echo Stopped Celeritas restart: stop start
关键注意事项
- 必须确保所有目标下的命令行前是单个Tab键,不要用空格代替(很多编辑器默认会把Tab转成空格,需在编辑器设置中关闭此功能)
- 路径在MinGW64环境中可以使用
/或\,但要注意拼写准确,避免输入错误 - 顺带修正了
run目标中的拼写错误(Staring改为Starting),同时调整了stop目标的提示文本更贴合实际操作
内容的提问来源于stack exchange,提问作者user63898
相关产品推荐
相关产品推荐

