CodeBlocks——windows配置

来源:互联网 发布:网络健康度检测插件 编辑:程序博客网 时间:2024/06/07 07:35

从VS2013到VS2017,我一直坚持不懈的使用VS系列(配合VSCode)来编写c/c++,但当初固态硬盘只装了128G的我越来越意识到c盘空间的珍贵,所以入坑CodeBlocks大法。
虽然CodeBlocks也是功能完备的一款IDE,但还是让我费了一点心思。
刚打开时会提醒选择编译器,没有细看直接进去了,果然新建工程后的HelloWorld都编译没有通过。
build时报错如下(我相信很多人都没有仔细看output里报错的习惯,我也是,直到最后一遍才看到……)

"test - 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.Skipping...

CodeBlocks如果在刚进入的时候你没有选择特定的编译器(compiler),IDE默认为GUN GCC conpiler,这里也说明了CodeBlocks并没有自带编译器,编译器需要自己下载配置,一般使用MinGW,不太熟悉的同学移步SublimeText 编译环境配置——windows
但配置好编译器后,CodeBlocks还是报错,为什么呢?看报错的第二句:编译器路径没有正确设置
第三句就开始教你在哪设置工具链下的编译器配置了:跟着做就好

Settings->Compiler…->Global compiler settings->GNUGCC Compiler->Toolchain executables

打开Setting选择Toolchain executables

compiler settings

图中可能需要更改的选项如图

change needed

Compiler’s installation derectory

这是MinGW安装的路径,默认为C:\MinGW,但很少有人直接安装在c盘根目录下,所以自行更正。
注意:直接填MinGW的安装路径,不要填它的bin路径

其他项

其他项是要调用的编译器的名字,MinGW后的Auto-Detect貌似不太智能,所以需要手动改正,因为版本不同,编译器的名字不太一样,老版本的MinGW名字都是mingw-32-XXX.exe,目前我用的新版本名字都直接是XXX.exe,具体是什么,请自行到MinGW的bin目录下对应查找类似的名称更改过来就好。
注意:make的名称也要更改过来,一次到位,防止后续再出类似问题

Hello World

上述更改完后,最好先将工程rebuild一下,如果不报错,再run即可
Hello World