c++ - C++ 中带有 Bash 终端 (WSL) 的 Visual Studio Code 仅构建 .out 文件 - 而不是 .exe
问题描述
我在带有 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 - 但 64 位版本x86_64-w64-mingw32-g++
不知何故不起作用。创建一个无效的 exe。
推荐阅读
- quantmod - 无法让 Pinescript 策略发挥作用,显示“无数据”
- laravel - 更改现有列以在迁移中具有默认值
- javascript - 如何对数组中的特定元素求和?
- r - 使用我的 ifelse 语句未正确拉出字符串
- go - Golang 加密/tls 内存泄漏
- docker - Dockerfile VOLUME 不挂载主机
- python - 熊猫:将列与日期时间值进行比较
- java - Java JSoup 从页面获取每张图片
- python - 一个项目 两个应用程序 两个静态文件夹 - django
- javascript - 创建一个函数,在单行上输出具有不同链接的链接文本,如果链接存在,则将链接映射到文本