Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilling C++ in visual studio code on Ubuntu

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.

like image 671
amplifier Avatar asked Dec 23 '22 02:12

amplifier


1 Answers

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.

like image 168
Ashford Nichols Avatar answered Dec 25 '22 14:12

Ashford Nichols