如何在使用Makefile构建后在cmd中运行该程序?

How to run the program in cmd after in builds with a Makefile?

本文关键字:运行 程序 cmd 构建 Makefile      更新时间:2023-10-16

我正在努力寻找一种方法,以便我的Makefile在构建后cmd执行构建的代码,我正在使用Sublime Text 3并且我正在尝试构建一个带有外部标头的c++文件。

这是我得到的(它显示了崇高文本"建筑结果"控制台中的初始菜单(:

function1 = Aleatori
main = main
language = g++
flags = -c
all: compile run
compile: main.o Aleatori.o #function2.o-
$(language) $(main).o $(function1).o -o $(function1).exe
main.o: $(main).cpp
$(language) $(flags) $(main).cpp
Aleatori.o: $(function1).cpp
$(language) $(flags) $(function1).cpp
.PHONY: clean
clean:
rm -f *.obj
.PHONY: run
run:
./$(function1)

如前所述,它只是输出程序的初始菜单,我无法与之交互。

g++ main.o Aleatori.o -o Aleatori.exe
./Aleatori
Benvingut al Brain Training Game! Si us plau, selecciona una dificultat:
1 - Facil
2 - Mig
3 - Dificil

感谢您的关注。 :)

终于让它工作了,以防有人对它感兴趣:

  • 我删除了制作文件的"运行部分">
  • 制作了一个自定义make.sublime_build,在 cmd 中调用"make"后运行程序。
  • 不得不重新安装我的mingw并安装包含mingwmsys2

make.sublime_build:

{
"cmd": ["make", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name}.exe"],
"file_regex": "^(..[^:n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${folder:${project_path:${file_path}}}",
"selector": "source.makefile",
"syntax": "Packages/Makefile/Make Output.sublime-syntax",
"keyfiles": ["Makefile", "makefile"],
"shell": true,
"variants":
[
{
"name": "Clean",
"shell_cmd": "make clean"
}
]
}