简体   繁体   English

在 Ubuntu 上的 Visual Studio 代码中编译 C++

[英]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 .我放入了从这里复制的 tasks.json 配置。

{
  "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:但是当我构建 (ctrl+shift+b) 时出现错误:

usr/bin/ld:/home/username/LinuxProjects/FirstCppProject/.vscode/tasks.json: file format not recognized; usr/bin/ld:/home/username/LinuxProjects/FirstCppProject/.vscode/tasks.json:文件格式无法识别; 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视为链接器脚本 /usr/bin/ld:/home/username/LinuxProjects/FirstCppProject/.vscode/tasks.json:1: 语法错误 collect2: 错误: ld 返回 1 退出状态终端进程以退出代码终止:1

I don't understand what's wrong with the json.我不明白 json 有什么问题。

This is compiling the currently active file, so you have to ensure you have the intended source file is active (ie 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.如果在 task.json 文件处于活动状态时运行此命令,它将尝试编译 task.json 文件。

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

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