尝试使用 MinGW 编译时出错:无法执行 cc1plus

error when trying to compile with MinGW: cannot execute cc1plus

我使用 GUI 安装程序在 Windows 7 32 位上干净安装了 MinGW,并安装了

当尝试从 cmd.exe 编译一个简单的“Hello World.cpp”时,我收到错误:

C:\Users\Lorenzo\Desktop>g++ "Hello World.cpp" -o"Hello World.exe" -m32 g++: fatal error: cannot execute 'cc1plus': CreateProcess: No such file or directory. compilation terminated.

奇怪的是,通过从桌面抓取文件并将其放在 MinGW 目录中的 g++.exe(以便我使用应用程序打开文件),我没有收到任何错误。

我发现的一个临时修复方法是让一个新的环境变量指向 cc1plus 所在的文件夹 (C:\MinGW\libexec\gcc\mingw32.2.0)。该程序运行但不包括来自 C:/MinGw/lib 和 C:/MinGw/Include 的库,我必须手动包括那些,这不应该发生(我猜)。 我不想做这个粗略的修复,因为我知道随着时间的推移我会遇到一些其他问题。

好的。我很幸运地找到了解决方案。

g++

中添加.exe就这么简单
> g++.exe *input file* -o*output.exe*

不知道是不是错误,但这对我有用。

我不确定你具体用的是哪个MinGW,不过最好用MinGW-w64。 您可以从 http://winlibs.com/ 获得不需要安装的独立版本。该站点还提供了一些有关如何使用它的说明。