c++ - 在 C++ 中使用 Bash 终端 (WSL) 的 Visual Studio Code 仅构建 .out 文件 - 而不是 .exe

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

我在带有 Linux 子系统的 Windows 10 上使用 Visual Studio Code。 (Ubuntu)

我创建了一个小的 c++ 文件,当我使用 bash 终端构建它时 - 只创建了一个 .out 文件。这很好,但我也想调试它,在那种情况下 - 我只能打开 .exe 文件。

当我从 bash 切换到 powershell 时 - 构建扩展是一个 .exe

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo",
      "type": "shell",
      "command": "g++",
      "args": [
        "-g", "main.cpp"
      ],
      "group": { "kind": "build", "isDefault": true }
    }
  ]
}

launch.json for debugging 

{
      "name": "(gdb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/a.exe", // .out doesn't work here
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
      "preLaunchTask": "echo",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }

main.cpp

#include <iostream>

int main() {
  std::cout << "hello a" << std::endl;
}

我真的不确定该怎么做 - 因为我无法调试 .out 文件并且我想自己选择构建扩展。

最佳答案

找到解决方案:

sudo apt-get install mingw-w64

然后在 tasks.json 里面

"command": "i686-w64-mingw32-g++"

这编译了一个 32 位 exe - 但是带有 x86_64-w64-mingw32-g++ 的 64 位版本不知何故不起作用。创建无效的 exe。

关于c++ - 在 C++ 中使用 Bash 终端 (WSL) 的 Visual Studio Code 仅构建 .out 文件 - 而不是 .exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50184511/

相关文章:

c++ - 使用 volatile 标准模板对象的方法

c++ - boost managed_mapped_file : setting maximum allowed memory usage

reactjs - VSCode : Cannot find module 'antd' or its corresponding type declarations

bash 本地化不适用于多行字符串(具有强语法或通过 `eval` )

java - 关闭 Android 模拟器后 OpenJDK 继续运行

python - 运行代码时输出面板中没有输出 - VSCode 上的 Python

c++ - 如何重载继承类中的方法,以便基类看到继承的版本?

c++ - 从过时的 DAO 类迁移

json - 如何将两个简单的 JSON 数组与 JQ 合并在一起

linux - shell 脚本 - 如何在不在脚本中定义变量的情况下为 shell 脚本使用变量