【问题标题】:g++ error in vscode: no such file or directoryvscode中的g ++错误:没有这样的文件或目录
【发布时间】:2021-08-04 07:30:01
【问题描述】:

在 VSCode 中,每当我尝试编译 cpp 文件时,都会收到以下错误:

> Executing task: 'C:\Program Files\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g d:\helloworld\helloworld.cpp -o d:\helloworld\helloworld.exe <

g++.exe: error: d:helloworldhelloworld.cpp: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

tasks.json 文件如下所示:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "cpp.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\cpp.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }
    ]
}

【问题讨论】:

  • 您阅读过GCC 的文档吗? VSCode 的?您是否尝试在终端中运行 g++ 命令?注意你的working current directory ...考虑在你的笔记本电脑上安装一个Linux发行版(例如Ubuntu ...)。
  • 我查看了 VSCode 教程,但没有帮助。关于安装 ubuntu,我不认为这是一个与 windows 相关的问题
  • 但是你读过documentation of GCC 吗?如果您花几个小时阅读该文档,您会发生什么? MinGW 也有一些文档......
  • 您是否尝试过使用正斜杠,例如将d:\helloworld\helloworld.cpp 替换为d:/helloworld/helloworld.cpp ?
  • @BasileStarynkevitch 非常感谢。阅读 GCC 文档确实很有帮助。

标签: c++ visual-studio-code compiler-errors g++


【解决方案1】:

感谢@Basile Starynkevitch,阅读文档有所帮助。这似乎工作正常:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CPP - BUILD FILE",
            "type": "shell",
            "command": "g++ -o ${fileBasenameNoExtension}.exe ${relativeFile}",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

【讨论】:

  • 我强烈推荐使用g++ -Wall -Wextra 而不是g++。你可能想要调试信息,所以g++ -Wall -Wextra -g
  • @BasileStarynkevitch 好的,我会添加这些
  • 我也建议-O3 -pedantic -pedantic-errors。对于调试版本:-fsanitize=address -fsanitize=undefined 真的很有帮助。
  • @TedLyngmo 可能是赞成票???大声笑只是在开玩笑,但如果您认为答案对其他人有帮助,那么请考虑给我一个支持
猜你喜欢
  • 1970-01-01
  • 2011-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
  • 1970-01-01
相关资源
最近更新 更多