简体   繁体   English

g ++ Task找不到用于简单构建的文件

[英]g++ Task can't find files for simple build

I'm trying to get started with using VS Code with WSL. 我正在尝试将WS Code与WSL一起使用。 I can use g++ to compile just fine in the terminal, but when I try to set this up using tasks it can't find the source files. 我可以在终端中使用g ++进行编译,但是当我尝试使用任务进行设置时,找不到源文件。

For illustration here's the output when I try with a simple hello world C++ program. 为了便于说明,下面是尝试使用简单的hello world C ++程序时的输出。 I've shown a simple build task as well as an ls to show that the file is there. 我已经显示了一个简单的构建任务以及一个ls,以表明该文件已存在。 Both of these tasks were run while my focus was on the source code file window. 我专注于源代码文件窗口时,同时运行了这两项任务。

Executing task: g++ helloworld.cpp <
>g++: fatal error: no input files compilation terminated.
>Terminal will be reused by tasks, press any key to close it.

>Executing task: ls <
>helloworld.cpp
>Terminal will be reused by tasks, press any key to close it.  

I guess I must just have some fundamental misunderstanding? 我想我必须有一些基本的误解? Needless to say when I close the terminal created by the task and try to just build from the command line it works. 不用说,当我关闭由任务创建的终端并尝试从命令行构建它时,它就起作用了。

testvscpp$ ls
helloworld.cpp
testvscpp$ g++ helloworld.cpp
testvscpp$ ls
a.out helloworld.cpp

Any help would be appreciated. 任何帮助,将不胜感激。

EDIT: The build task was as follows. 编辑:构建任务如下。

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Simple build",
            "type": "shell",
            "command": "g++",
            "args": [
                "helloworld.cpp"
            ]
        },
        {
            "taskName": "Show ls",
            "type": "shell",
            "command": "ls"
        }
    ]
}

Which is only slightly different from the version found in the documentation - however I also tried this exactly and it didn't work either. 这与文档中找到的版本仅稍有不同-但是我也尝试过此操作,但也没有用。

Under "args": , the argument -g is required: "args": ,参数-g是必需的:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Simple build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "helloworld.cpp"
            ]
        },
        {
            "taskName": "Show ls",
            "type": "shell",
            "command": "ls"
        }
    ]
}

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

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