在Visual Studio 2017中,“使干净”的任务配置不起作用

时间:2018-10-14 15:04:22

标签: c visual-studio makefile

我写了这个简单的程序:

main.c:

#include "main.h"

void nothing(){}

int main(){
  nothing();  
  return 0;
}    

main.h:

void nothing();                   

现在使用以下通用Makefile编译并运行它:

CC = gcc
CC_FLAGS = -g
EXEC = run
SOURCES = $(wildcard *.c)
OBJECTS = $(SOURCES:.c=.o)

$(EXEC): $(OBJECTS)
    $(CC) $(OBJECTS) -o $(EXEC)

%.o: %.c
    $(CC) -c $(CC_FLAGS) $< -o $@

clean:
    rm -f $(EXEC) $(OBJECTS)

现在,我想使用VS进行编译和运行,但是编译和清理(通过make clean)必须由makefile执行。因此,我在VS中打开了程序的文件夹(包含所有3个文件),并在tasks.vs.json上为其配置了以下任务:

{
  "version": "0.2.1",
  "tasks": [
    {
      "taskName": "BUILD",
      "appliesTo": "/",
      "workingDirectory": "${workspaceRoot}",
      "command": "make",
      "type": "default"
    },
    {
      "taskName": "CLEAN",
      "appliesTo": "/",
      "workingDirectory": "${workspaceRoot}",
      "command": "make clean",
      "type": "default"
    }
  ]
}

BUILD的任务有效,但CLEAN的任务得到:

'"make clean"' is not recognized as an internal or external command,      
operable program or batch file.                 

您知道如何为CLEAN修复我的任务,以便它可以按我的意愿进行清理吗?

1 个答案:

答案 0 :(得分:1)

作为"command"的值给出的字符串被解释为单个命令。要将参数发送给命令,例如clean,该架构提供了给出参数数组的可能性。就您而言,它看起来像这样:

      "command": "make",
      "args": [ "clean" ],