g ++exe:安装问题,不能执行“ as”:没有这样的文件或目录

问题描述

我正在尝试学习C ++,我按照此教程使用Cygwin在Windows上下载并安装了g ++: https://www.cs.odu.edu/~zeil/cs250PreTest/latest/Public/installingACompiler/#installing-the-mingw-compiler

就像在本教程中一样,最后,我检查是否已安装g ++:

PS D:\Desktop\coursera_ODS_in_c-\Week 2> g++ --version
g++.exe (GCC) 3.4.5 (mingw-vista special r3)
copyright (C) 2004 Free Software Foundation,Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or fitness FOR A PARTIculaR PURPOSE.

然后尝试运行以下代码

#include <iostream>

int main() {
    int num = 7;
    
    std::cout << "Values:" << num << std::endl;
    std::cout << "Address: " << &num << std::endl;
    return 0;
}

使用此

PS D:\Desktop\coursera_ODS_in_c-\Week 2> g++ main.cpp

但是我明白了:

g++.exe: installation problem,cannot exec `as': No such file or directory

您如何解决这个问题?

解决方法

消息:

g++.exe: installation problem

明确指出G ++编译器的安装有问题。另外,3.4.5版本太旧了。当前的稳定版本是10.2(于2020年7月23日发布),重新安装最新版本可能会解决您的问题。 (由于给出的详细信息不足,导致错误的原因仍然是个谜。)

尝试下载最新版本GNU GCC随附的GNU GCC编译器。

OTOH,程序已正确编码,OnlineGDB上未报告错误。