g ++构建在错误的目录中:$ {workspaceFolder} \ file.exe而不是$ {fileDirname} \ file.exe

问题描述

摘要:

虽然在task.json中,g ++的目标参数显然是"${fileDirname}\\${fileBasenameNoExtension}.exe",但它决定在"${workplaceFolder}\\${fileBasenameNoExtension}.exe"中构建...

示例:

文件夹结构:

  • cpp
    • .vscode
      • tasks.json
    • 文件夹1
      • 文件夹2
        • example.cpp

在task.json中:

{
    "version": "2.0.0","tasks": [
    {
      "type": "cppbuild","label": "C/C++: g++.exe build active file","command": "C:\\dev\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe","args": [
        "-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],"options": { "cwd": "C:\\dev\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin"  },"problemMatcher": [ "$gcc" ],"group": { "kind": "build","isDefault": true   },"detail": "compiler: C:\\dev\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe"
    }
  ]
}

在example.cpp中:

#include <iostream>
int main()
{
  std::cout << "Why do i not get compiled in "cpp/folder1/folder2"?";
  return 0;
}

在vscode中,将cpp文件夹作为工作场所打开: 现在,按Ctrl + Shift + B组合键即可使g ++在cpp / example.exe上构建example.exe。

解决方法

请以某种方式提供Minimal,Reproducible Example。它可以帮助人们了解您的问题,因此我们可以更轻松地为您提供答案。

从您的问题中我可以理解,也许您只是将.exe文件编译到了另一个目录中? (同样,由于您未提供任何Minimal,Reproducible Example,因此我无法完全理解您的错误)

也许尝试在args中放入类似内容:

"-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"
,

已知问题和昨天解决的问题。必须等待下一个C / c ++ vscode扩展更新:

https://github.com/microsoft/vscode-cpptools/issues/6501

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...