简体   繁体   English

带有“Make”构建系统的 Sublime Text 3 不运行该程序

[英]Sublime Text 3 with "Make" build system doesn't run the program

I am trying to build a C++ project in Sublime Text 3 on Linux. Normally I just swap to the terminal and run make run and it runs.我正在尝试在 Linux 上的 Sublime Text 3 中构建一个 C++ 项目。通常我只是切换到终端并运行make run ,它就会运行。 However, I'm trying to streamline the process by running directly in Sublime.但是,我试图通过直接在 Sublime 中运行来简化流程。 However, pressing Ctrl+Shift+B brings up only two options: Make and Make clean.但是,按 Ctrl+Shift+B 只会出现两个选项:Make 和 Make clean。 Both of which will do the command according to my Makefile for the project.两者都将根据我的项目 Makefile 执行命令。 However, there is no Make run, so I can't directly run the project by pressing Ctrl+B.但是没有Make run,所以我没法直接按Ctrl+B运行工程。 I hope someone can provide some insight into this!我希望有人能对此提供一些见解!

Here is my Makefile:这是我的 Makefile:

BINARY := build/project
SRCS := $(shell find . -iname "*.cpp")
OBJS := $(addprefix build/,$(SRCS:.cpp=.o))

NEEDED_LIBS := 

CXX := g++ -flto
LD := $(CXX) $(addprefix libs/,$(NEEDED_LIBS))
override CXXFLAGS += -std=c++11
override LDFLAGS += $(CXXFLAGS)

all:$(BINARY)

$(BINARY):$(OBJS) $(addprefix libs/,$(NEEDED_LIBS))
    $(LD) $(LDFLAGS) -o $@ $^

build/%.o:%.cpp
    $(CXX) -O2 -c $(CXXFLAGS) $< -o $@

run:$(BINARY)
    @$(BINARY)
    
clean:
    rm -rf build/*

The default build for this is Makefile/Make.sublime-build , which looks like this:默认构建是Makefile/Make.sublime-build ,它看起来像这样:

{
    "shell_cmd": "make",
    "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"],

    "variants":
    [
        {
            "name": "Clean",
            "shell_cmd": "make clean"
        }
    ]
}

That is, by default it just runs Make , but it also has a variant named Clean that will run make clean as well.也就是说,默认情况下它只运行Make ,但它还有一个名为Clean的变体,它也会运行make clean In particular, this points out that the list of commands is static and doesn't rely on the actual content of the Makefile in question.特别是,这指出命令列表是 static 并且不依赖于所讨论的 Makefile 的实际内容。

What you can do is choose Tools > Build System > New Build System from the menu, which will create a new tab and provide a default build system.您可以做的是从菜单中选择Tools > Build System > New Build System ,这将创建一个新选项卡并提供默认构建系统。 Select all of that content, and then replace it with a copy of the above so you have a duplicate of the base build system. Select 所有这些内容,然后用上面的副本替换它,这样你就有了基本构建系统的副本。 Then, you can add in additional variants as needed.然后,您可以根据需要添加其他变体。 For example:例如:

    "variants":
    [
        {
            "name": "Clean",
            "shell_cmd": "make clean"
        },
        {
            "name": "Run",
            "shell_cmd": "make run"
        }
    ]

Once you're done, save the file in the location Sublime defaults to (your User package) with a custom name, like Custom Makefile.sublime-build or such (the location and the extension are the important parts).完成后,使用自定义名称将文件保存在 Sublime 默认的位置(您的User包),例如Custom Makefile.sublime-build等(位置和扩展名是重要部分)。

Once you've done that, you will see your build system appear in the menu under Tools > Build System with the name that you saved the file as.一旦你这样做了,你会看到你的构建系统出现在Tools > Build System下的菜单中,并带有你保存文件的名称。 You can either select the build there to use it, or leave it set as automatic.您可以 select 那里的构建来使用它,或者将其设置为自动。

When you use ctrl+shift+b next, the options from this build system will appear in the list (if the build is set to automatic, you'll see the default options as well).当您接下来使用ctrl+shift+b时,此构建系统的选项将出现在列表中(如果构建设置为自动,您也会看到默认选项)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM