您的位置:首页 > 其它

【笔记】Code::Blocks

2014-03-17 21:53 926 查看

Code::Blocks

1) Windows上安装与编译

1.1) 安装C::B

已有MinGW的下载
codeblocks-?.?-setup.exe
即可,还没有的推荐直接下载
codeblocks-?.?mingw-setup.exe


1.2) 配置MinGW

添加环境变量:

Path += %MinGW%\bin;%MinGW%\mingw32\bin;

MinGW之后编译Code::Blocks要用。

At the present time, Code::Blocks only compiles successfully with the MinGW compiler (or any other gcc for that matter).

1.3) 编译wxWidgets

svn: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk

mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1

编译详见参考2,过程会比较久。可以直接下载预编译好的,在这儿

For Windows, we also provide the pre-compiled wxWidgets, ...

自己编译的话,就直接上wxWidgets3.0,参考5.1。

1.4) 编译Code::Blocks

svn: http://my.oschina.net/vaero/blog/svn:/svn.code.sf.net/p/codeblocks/code/trunk

假设:

D:\codeblocks  # Code::Blocks源码目录
D:\wxMSW-2.8.12  # 预编译wxWidgets解压目录


打开Code::Blocks,然后"File > Open...: D:\codeblocks\src\CodeBlocks.cbp"。

在弹出"Global Variable Editor"内(可由"Settings > Global variables..."打开):

Current Set: default, Current Variable: wx: Built-in fields > base: D:\wxMSW-2.8.12

Current Set: default, Current Variable: cb_release_type: Built-in fields > base: -o2

设置MinGW编译,"Settings > Compiler...":

Selected compiler: GNU GCC Compiler > Toolchain executables: [MinGW]\bin

工具栏 > Build Target: Compiler,然后Build。(Error: cannot find -lcodeblocks|-ldepslib)

Build All吧,-lcodeblocks(Target sdk)往上依赖很多。

需要zip.exe,列在了tools page。下载并加到Path。(Execution of zip ... failed.)

zip建议直接下载
zip-?.?-setup.exe
安装。如果只是bin的话,还依赖bzip2

如果要显示SVN修订号,则需要svn.exe,这儿下载。否则为0。

注意:3视情况,456不用依步骤,7随意。

然后:

拷贝"D:\wxMSW-2.8.12\lib\gcc_dll\wxmsw28u_gcc_cb.dll"到"D:\codeblocks\src\devel"目录。

运行"D:\codeblocks\src\update.bat",目录"D:\codeblocks\src\output"下就是你的发行版了。

运行"D:\codeblocks\src\output\codeblocks.exe"时,由于单例,记得关闭开着的C::B。

可以卸载原先安装的C::B,用"output"下的迭代编译自身。

1.5) 参考

Retrieve source code from SVN

Installing Code::Blocks from source on Windows

windows 环境下编译 Code::Blocks

2) 基本配置

Settings
-> Editor...
-> General settings
-> Editor settings
-> Font > Choose
-> F = YaHei Consolas Hybrid  # 等宽字体
-> TAB options
-> TAB size in spaces = 4  # TAB为4个空格
-> End-of-line options
-> End-of-line mode = AUTO  # 自动。
# 想选UNIX换行符LF,但现在换行符都由版本控制系统根据平台自动做转换了。
-> Other options
-> Highlight line under caret  # 高亮光标所在行
-> Other settings
-> Encoding
-> Use encoding when opening files = UTF-8  # 打开文件默认编码
-> Use this encoding: As default encoding  # 默认编码
-> Other options
-> Show spaces in editor = Always  # 总显示空格
-> Margins and caret
-> Right margin
-> Right margin hint = Visible line  # 右边界线可见
Edit
-> File Encoding  # 选择文件编码

新建Console application,由于Windows下Command Prompt不支持UTF-8,如果输出中文会是乱码。用的GCC编译器的话,可以设置-fexec-charset=GBK,即执行时字符集为GBK。更多选项

Settings
-> Compiler...
-> Selected compiler = GNU GCC Compiler
-> Compiler settings
-> Other options: -fexec-charset=GBK

需要Rebuild后再Run。

3) 进行调试

3.1) Hello World

与"-fexec-charset=GBK"一样的步骤,添加"-std=c++11"以使用新特性。

File > New > Project... > Console application,依步骤建立个Hello World工程。

main.cpp稍改复杂些,以试单步调试,如下:

main.cpp

#include <iostream>
#include <string>
#include <vector>

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec)
{
for (auto& el : vec)
{
os << el << ' ';
}
return os;
}

int main()
{
std::vector<std::string> words = {
"Hello", "from", "GCC", __VERSION__, "!"
};
std::cout << words << std::endl;
}

3.2) 进行Debug

Settings > Debugger... > GDB/CDB Debugger > Default > Executable path,设Debugger程序。

在第8行"for (auto& el : vec)"打断点,然后Debug运行即可。

Debug时,Debugger > Debugging windows或工具栏,可添加Debug窗口。Layout会被记录。

3.3) 参考

Debugging with Code::Blocks

4) 常用快捷

Editor

功能快捷键
复制当前行Ctrl-D
删除选中行Ctrl-L
删除光标所在行Ctrl-Shift-L
与上行交换Ctrl-T
到上一段落Ctrl-[
到下一段落Ctrl-]
撤销/UndoCtrl-Z
恢复/RedoCtrl-Shift-Z
切换头文件与源文件F11
注释Ctrl-Shift-C
取消注释Ctrl-Shift-X
自动完成Ctrl-J
切换书签Ctrl-B
到上个书签Alt-PgUp
到下个书签Alt-PgDown
Search

功能快捷键
查找Ctrl-F
查找下个F3
查找上个Shift-F3
在文件中查找Ctrl-Shift-F
替换Ctrl-R
在文件中替换Ctrl-Shift-R
到指定行Ctrl-G
到下个被改变的行Ctrl-F3
到上个被改变的行Ctrl-Shift-F3
到指定文件Alt-G
到指定函数Ctrl-Shift-G
到上个函数Ctrl-PgUp
到下个函数Ctrl-PgDown
到声明处Ctrl-Shift-.
到实现处Ctrl-.
打开include文件Ctrl-Alt-. # 冲突,见5.1
到匹配括号Ctrl-Shift-B
View

功能快捷键
显示/隐藏信息板F2
显示/隐藏管理板Shift-F2
上移工程Ctrl-Shift-Up
下移工程Ctrl-Shift-Down
激活上个项目Alt-F5
激活下个项目Alt-F6
Build

功能快捷键
BuildCtrl-F9
编译当前文件Ctrl-Shift-F9
RunCtrl-F10
Build and RunF9
RebuildCtrl-F11
Debug

功能快捷键
切换断点F5
调试/继续F8
运行到光标处F4
单步下行代码F7
单步进入子函数Shift-F7
单步跳出子函数Ctrl-F7
单步下条指令Alt-F7
单步进入子指令Shift-Alt-F7
参考

Keyboard Shortcuts

5) 插件

5.1) keybinder(Keyboard Shortcuts)

location: D:\codeblocks\src\plugins\contrib\keybinder

修改快捷的插件,但只看到了wx3.0工程版本==。因而,还是要准备下wxWidgets3.0。

注:plugins分为3类,contrib下是社区贡献的非常有价值的插件,所以整合到了SVN。见参考1。

5.1.1) MinGW编译wxWidgets3.0

wxWidgets3.0 svn: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/WX_3_0_0-rc2/

假设源码目录为"D:\WX_3_0_0-rc2"。则到"D:\WX_3_0_0-rc2\build\msw"目录。

2.1 修改config.gcc,防止连接时内存不够用。

CFLAGS ?= -fno-keep-inline-dllexport
CXXFLAGS ?= -fno-keep-inline-dllexport

2.2 然后,如下编译wxWidgets3.0:

mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 clean
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1

编译详看参考3,4。

5.1.2) 编译Code::Blocks

同1.4,不过:

打开"CodeBlocks_wx30.cbp"(注意还有其他区分),而不是"CodeBlocks.cbp"。

"Global Variable Editor"时,wx base设为"D:\WX_3_0_0-rc2",而不是"D:\wxMSW-2.8.12"。

继而:

拷贝"D:\WX_3_0_0-rc2\lib\gcc_dll\wxmsw30u_gcc_custom.dll"到"D:\codeblocks\src\devel30"目录。

运行"D:\codeblocks\src\update30.bat",目录"D:\codeblocks\src\output30"下就是你的发行版了。

5.1.3) 编译keybinder

打开"D:\codeblocks\src\plugins\contrib\keybinder\keybinder_wx30.cbp"(注意还有其他区分),Build即可。

然后重新"update30.bat",重新打开C::B。在Settings > Editor...下多了Keyboard shortcuts,然后重定义吧。

把"Search > Open include file"改为"Ctrl-Alt-.",其与"Goto declaration"冲突。(r9741)

5.2) 参考

Code::Blocks Plugins

Creating a simple "Hello World" plugin

Compile_wxWidgets_in_Unicode_mode

Compiling wxWidgets with MinGW

r9741 compile error with wx3.0 on Windows

6) 其他参考

User manual

译: Code::Blocks手册 使用篇

CodeBlocks的下载安装、配置、简单编程

Linux上安装与编译,参考:CentOS安装Code::Blocks
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息