简体   繁体   中英

g++ Task can't find files for simple build

I'm trying to get started with using VS Code with 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.

For illustration here's the output when I try with a simple hello world C++ program. I've shown a simple build task as well as an ls to show that the file is there. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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