4
votes

I'm trying to compile a very simple code. I put in tasks.json configuration copied from here.

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build & debug file",
      "type": "shell",
      "command": "g++",
      "args": [
        "-g",
        "-o",
        "${fileBasenameNoExtension}",
        "${file}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    },
    {
      "label": "build & run file",
      "type": "shell",
      "command": "g++",
      "args": [
        "-o",
        "${fileBasenameNoExtension}",
        "${file}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

But when I build (ctrl+shift+b) I get errors:

usr/bin/ld:/home/username/LinuxProjects/FirstCppProject/.vscode/tasks.json: file format not recognized; treating as linker script /usr/bin/ld:/home/username/LinuxProjects/FirstCppProject/.vscode/tasks.json:1: syntax error collect2: error: ld returned 1 exit status The terminal process terminated with exit code: 1

I don't understand what's wrong with the json.

1
Have you checked the end of line for this file? - Matthieu Brucher
what exactly should I check? - amplifier
Check that your end of line is Unix and not Windows. Have you downloaded the file from Windows, or Linux? - Matthieu Brucher
I copy-pasted it from the site via firefox in Ubuntu - amplifier
try to run dos2linux on the file (converts end of line from windows to linux) - Matthieu Brucher

1 Answers

10
votes

This is compiling the currently active file, so you have to ensure you have the intended source file is active (i.e. open and in view). If you run this command when the task.json file is active, it will attempt to compile the task.json file.