首页 > 解决方案 > 无法在 C++ 代码块中构建和运行

问题描述

所以我最近刚刚下载了一个名为 Code::Blocks 的 C++ IDE 并创建了一个新项目。但是当我尝试构建并运行它时,代码给出了一些错误。我知道这不是语法或类似问题的问题,因为我运行了 Code::Blocks 提供的默认代码。错误如下:

Project/Target: "firstcpp - Debug":
  The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.
  Probably the toolchain path within the compiler options is not setup correctly?!
  Do you have a compiler installed?
Goto "Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.

Tried to run compiler executable 'C:\MinGW/bin/gcc.exe', but failed!

Skipping...
Nothing to be done (all items are up-to-date).


在我看来,C++ 编译器存在某种问题,但我认为 Code::Blocks 已经带有 C++ 编译器,所以我不太确定这里有什么问题。我也按照他们的指示去了Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables,但我不太清楚他们的意思fix the compiler。这是我所看到的屏幕截图:

如果您需要,这里还有我电脑上的信息:

在这一点上,我不太确定如何解决这个问题。我问过朋友这个问题(他们已经成功下载并使用了Code::Blocks),他们说他们在安装的时候从来没有遇到过这个问题。

标签: c++gcccompiler-errorscodeblocks

解决方案


您需要确保您拥有 GNU Compiler Collection 的有效安装,并且您为工具链选择的路径存在。

如果您尚未安装 GCC,最简单的方法是从下载站点下载与 MinGW 预先捆绑的 Code::Blocks 分发。但是,您也可以通过其他方式安装 GCC,例如:

bin无论哪种情况,您都需要在 Code::Blocks 中设置工具链时选择包含该目录的安装路径。


推荐阅读