【问题标题】:How to run the program in cmd after in builds with a Makefile?使用 Makefile 构建后如何在 cmd 中运行程序?
【发布时间】:2019-03-21 09:51:22
【问题描述】:

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

这是我得到的(它在 sublimetext“buildingresult”控制台中显示初始菜单):

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

感谢您的关注。 :)

【问题讨论】:

  • 拥有像compile: 这样的目标是不寻常的。通常我希望该目标是$(function1).exe:
  • 如果程序生成了一个可运行的可执行文件,makefile 通常会完成它的工作。是否考虑过源代码有错误的可能性?
  • 让我解释一下,这个makefile构建的程序没有问题,它运行完美,但我希望makefile在构建后运行它。
  • 您在 Windows 上吗?您的 makefile 正在创建文件 Aleatori.exe,但您的 run 目标正在调用程序 Aleatori。如果您在 Windows 上可能会工作(尽管这是不好的做法),但如果您在任何 POSIX 系统上,这些文件就不一样了。
  • 另外,请告诉我们您是如何调用make(您使用的完整命令行)

标签: c++ makefile sublimetext3


【解决方案1】:

终于搞定了,万一有人对它感兴趣:

  • 我删除了 makefile 的“运行部分”
  • 制作了一个自定义的 make.sublime_build,它在 cmd 中调用“make”后运行程序。
  • 必须重新安装我的mingw 并安装msys2,其中包含mingw

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"
        }
    ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-24
    • 2013-11-25
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2017-04-25
    相关资源
    最近更新 更多