【问题标题】:g++ Task can't find files for simple buildg ++任务找不到简单构建的文件
【发布时间】:2017-08-24 07:18:29
【问题描述】:

我正在尝试开始将 VS Code 与 WSL 结合使用。我可以在终端中使用 g++ 进行编译,但是当我尝试使用任务进行设置时,它找不到源文件。

为了说明,这是我尝试使用简单的 hello world C++ 程序时的输出。我已经展示了一个简单的构建任务以及一个 ls 来显示该文件在那里。这两个任务都是在我关注源代码文件窗口时运行的。

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.  

我想我一定只是有一些基本的误解?不用说,当我关闭由任务创建的终端并尝试从命令行构建时它可以工作。

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

任何帮助将不胜感激。

编辑:构建任务如下。

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

这与documentation 中的版本仅略有不同 - 但是我也完全尝试过,但它也没有工作。

【问题讨论】:

  • 抱歉没有回复!这对我不起作用。事实上,我在 VS Code Github 上发布过,结果发现这个问题与对 WSL 的支持不完全有关,但是解决方法是添加 ':;'到任务的参数列表。 github.com/Microsoft/vscode/issues/33232

标签: c++ g++ visual-studio-code windows-subsystem-for-linux


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多