使Code::Blocks适合ARM开发

Adapting Code::Blocks IDE for ARM Development [1]
使Code::Blocks适合ARM开发

This brief guide can be followed after the ARM-GCC toolchain is setup.
在安装过ARM-GCC工具链后,即可按照此简明指南来做。

For instructions to setup the ARM-GCC toolchain,
refer to the “Setting up the ARM-GCC Toolchain on Windows” page of this site.
对于安装ARM-GCC工具链的用法说明,参考本站的“Windows下ARM-GCC工具链的安装”[2]

I recently found perhaps the only other suitable IDE for Windows
named Code::Blocks.
我最近找到的适合IDE也许只有Windows下的Code::Blocks了。
注:Ubuntu下也可以用Code::Blocks,到我翻译这篇文章止版本为8.02。

Unlike Eclipse, it’s slim, fast and native.
不像Eclipse,它是小巧、快速、原生(不依赖其它平台运行,如Java、.net平台)。

Like Eclipse, it’s highly configurable and can be used with GCC.
像Eclipse一样,它具有高度可配置性并且可以使用GCC。

In addition,
Code::Blocks can be easily used with
GDB to debug your code (major factor in choosing another IDE).
另外,Code::Blocks 可以容易的使用GDB来调试你的代码(挑选类似IDE的主要因素)。

This is good to use later with OCDRemote/gcc to
debug your ARM code (although I haven’t configured it, yet.)
以后使用OCDRemote/gcc[3]调试你的ARM代码也会很好(虽然我还没有配置它)。

So here are the instructions for setting up the Code::Blocks to work with
the ARM GCC toolchain.
所以这里是建立Code::Blocks与ARM GCC工具链共同工作的用法说明。

To do this,
all that needs to be done is configuring Code::Blocks to
use an external Makefile,
but finding the location of these settings took a rather long time.
为了做到这点,
必须完成配置Code::Blocks使用一个外部的Makefile文件,
仅仅找这些配置的位置就花费了很长时间。

Step One – Create a New Project
第一步 - 创建一个新工程

Since none of the included project templates really fit for
ARM GCC development,
it’s easiest to start out by making a new blank project.
由于ARM GCC开发空工程模板很合适,因为一个空的新工程是最容易着手进行的。

So do this by clicking on the “Project” menu, then “New empty project”.
新建空工程通过点击“工程”菜单项,然后选择“新建空工程”。(如下图)
使Code::Blocks适合ARM开发_第1张图片 

注:Ubuntu下的Code::Blocks v8.02新建空工程方式有所不同,详见下图:
使Code::Blocks适合ARM开发_第2张图片  

使Code::Blocks适合ARM开发_第3张图片

由于无法在Ubuntu上调试故此只创建“Release”配置即可!(IDE要求必须创建一个Debug或Release的配置)

使Code::Blocks适合ARM开发_第4张图片

点击上面界面的Finish按钮后,
你就点击[Build]菜单 -> [Rebuild] 或 [Rebuild workspace]菜单项,编译空工程的话,
就会从编译日志标签“Build log”得到如下错误提示:
make: *** 没有规则可以创建目标“Release”。 停止。
Process terminated with status 2 (0 minutes, 0 seconds)
0 errors, 0 warnings

解决方法自然是添加源代码文件与其相关的头文件了!Makefile文件也可以添加,会放入 Others 分类中。
使Code::Blocks适合ARM开发_第5张图片

注:添加完文件后,再点击[project]菜单 -> 选择[Build options...]菜单项 ->
    删除 "Make" commands 选项卡内所有 $target


Save the project in the folder of your project,
where you plan to hold the code.
保存这个新建的空工程到你想要保存代码的目录文件里。

You will see several window panes in the IDE.
你将在这个IDE里看见几个窗格。

I will briefly describe them here:
我将这里简略地描述它们:

1)Management Pane 管理窗格
使Code::Blocks适合ARM开发_第6张图片

The Management Pane contains three tabs that are all somehow related to the code itself.
这个管理窗格包含三个不同方式来讲述代码的标签。

First is the “Projects” tab,
which lists the opened projects in the workspace,
and the files that are associated with the project.
第一个是“工程”标签,列举这个工作空间中的全部工程与其文件。

The files are automatically separated into three sections: Sources, Headers, and Others.
文件自动区分为三组:源代码,头文件与其它。

Double-clicking on a file will bring it up for editing in the editor.
双击一个文件将可在编辑器中打开编辑。

Second is the “Symbols” tab, which outlines all of the functions, variables, enumerations,
preprocessor directives, and classes existing in the code of the project.
第二个是“符号”标签,概述工程代码中的全部的函数、变量、枚举、宏定义(预处理器指令)、类。

Double-clicking on any one of these elements will bring it up highlighted in the editor.
双击这些元素中的任意一个将可在编辑器中高亮显示。

The third and final tab is the “Watches” tab,
which is used to add debugging watches to variables.
这最后的第三个标签是“察看”,习惯用于调试察看变量。

2)Messages Pane 信息窗格
使Code::Blocks适合ARM开发_第7张图片
The Messages Pane stores the general output from several sources.
这个信息窗格汇集了若干源文件的总的信息输出。

It has tabs to easily switch between these message categories.
它有几个标签可以轻易地切换不同种类信息。

The “Code::Blocks” messages tab obviously holds the message output from
Code::Blocks itself,
which is usually irrelevant to development.
“Code::Blocks”信息标签包含显示来自Code::Blocks自身输出与开发无关的信息。

If a problem occurs with the IDE,
this would be a good place to check for troubleshooting.
如果这个IDE出现问题,这将是一个发现并修理故障的好地方。

The next tab is the “Search Results” tab,
which is pretty self-explanatory.
紧邻的标签很清楚是“搜索结果”标签。

Clicking on a search result will open the file and
highlight the line containing the search term(s) in the editor.
点击一个搜索结果将在编辑中打开文件并高亮显示包含搜索项的行。

The next tab is the “Build log”,
and holds the commands made to the compiler,
linker and other tools.
再紧邻的标签是“编译日志”,包含编译器,链接器和其它工具的命令日志。

Next is the “Build messages” tab,
which lists the errors or warnings present in the code that was caught by the compiler,
including the file and line number at which the error/warning is located.
再紧邻的是“编译信息”标签,列举编译器关于代码的错误或警告,其中文件与行号定位错误或警告。

The next tab is the “Debugger” tab,
which will contain the output of the chosen debugger.
再紧邻的标签是“调试器”标签,包含选定调试器的输出信息。

The final tab is the “To-Do List” tab,
which lists To-Do items that are present in the code.
这最后的标签是“任务列表”标签,列举代码中当前待办事项项目。

To-Do items are defined by Code::Blocks as a comment in code,
and can be added by right-clicking on
a line in the editor and clicking “Add To-Do Item…”.
待办事项是Code::Blocks在代码中定义的注释,可以点击由通过右键点击编译器中的一行弹出的菜单项“添加待办事项...”来添加。

3)Editor Window 编辑器窗口
使Code::Blocks适合ARM开发_第8张图片
Probably the most important part of the IDE, the text editor itself.
大概这个文本编辑器是IDE最重要的部分。

It supports syntax highlighting,
several forms of autocompletion,
collapsing code segments, and much more.
它支持语法高亮,自动完成输入,折叠代码段,等等。

It can be highly customized under the “Settings” menu, in the “Editor” settings.
可以在“设置”菜单中的“编辑器”菜单项中高度自定义。

Notably, the font, indentations, colors, and auto-completion can be configured.
显著地,字体,缩排,颜色,自动完成功能可以是配置的。

In addition,
“Default Code” can be defined to be written whenever
a new source/header file is created.
另外,“默认代码”可以在每当创建一个新源代码文件或头文件时写好已定义的文字内容。

Step Two – Configure Build Settings
第二步 - 配置编译设置

The next step is to setup Code::Blocks to
use an external Makefile instead of automatically and
directly calling GCC.
下一步是设置Code::Blocks使用一个外部的Makefile文件自动直接地调用GCC。

Click on the “Settings” menu, then “Compiler”.
点击“设置”菜单,然后“编译器”。

1. Keep your Selected Compiler as the “GNU GCC Compiler”.
1. 保持选择“GNU GCC Compiler”编译器。

2. Click on the “Other” tab.
2. 点击“其它”标签。

3. Change “Build Method” to “Work with Makefiles (GNU ‘make’ is required)”.
3. 改变“编译方式”为“按项目组成文件Makefiles工作(GNU make工具是必需的)”。

4. Click “OK” to close the window.
4. 点击“确定”关闭窗口。

使Code::Blocks适合ARM开发_第9张图片

Next the path of the Makefile must be defined.
在这之后Makefile的路径一定要确定。

Click on the “Project” menu, then “Properties”.
点击“工程”菜单,然后点“属性”。

1. Type the name of the external Makefile
     (given it is in the same directory as where the project is saved, if not,
       modify the path revelant to the project file or provide an absolute path)
     in the “Makefile:” textbox.
1. 键入外部的Makefile文件的名字(如果不是与保存工程的目录相同,则修改为相对或绝对路径)
   在“Makefile:”后的文本框中。

2. Check the “This is a Custom Makefile” checkbox.
2. “这是一个自定义Makefile”复选框选上(打上勾)。

3. Click “OK” to close the window.
3. 点击“确定”关闭窗口。

使Code::Blocks适合ARM开发_第10张图片

注:Code::Blocks 10.05 的以上界面中还多了一个 Execution directory 项,
  该项的值(绝对或相对路径)一定是 Makefile 文件所在的路径,
  为了在 Build messages 中双击错误信息能打开相应的源文件,
  请确保 *.cbp 文件与 Makefile 文件在同一目录下,
  所以 Execution directory 项的值应为 ./ ,
  只有这样才能让工程文件(*.cbp)中描述的文件与 Makefile 文件执行过程中产生错误提示的文件匹对上。

使Code::Blocks适合ARM开发_第11张图片



注:Ubuntu下Code::Blocks v8.02的使用自定义Makefile的设置如下:
一、 修改 GNU ARM GCC Compiler

1. [Settings] -> [Compiler and debugger settings]
    将Setected compiler 修改为GNU ARM GCC 编译器。
使Code::Blocks适合ARM开发_第12张图片 


2. 在同页面选择 [Toolchain executables]选项卡中的[program files]选项页,
    1) 先修改 Compiler's installation directory 为你的ARM GCC Compiler安装所在地址;
    2) 再选择替换C编译器(arrm-linux-gcc)、C++编译器(arm-linux-g++)、
        动态库链接器(arm-linux-g++)、静态库链接器(arm-linux-ar)、调试器(arm-linux-gdb);
    注:make程序还用/usr/bin/make,即GNU GCC 自带的即可!
使Code::Blocks适合ARM开发_第13张图片


二、点击[project]菜单 -> 选择[Properties...]菜单项 ->
    勾选 “This is a custom Makefile” 前的复选框
使Code::Blocks适合ARM开发_第14张图片

使Code::Blocks适合ARM开发_第15张图片

三、点击[project]菜单 -> 选择[Build options...]菜单项 ->
    删除 "Make" commands 选项卡内所有 $target

使Code::Blocks适合ARM开发_第16张图片 

使Code::Blocks适合ARM开发_第17张图片 

Here is a list of several features Code::Blocks features which
you can further configure if you please:
这里是一些你愿意进一步配置Code::Blocks的若干特征列表:

  1) Intellisense-like Completion
  1) 智能感知输入提示完成

  2) Keyword Auto-Completion
  2) 关键字自动完成

  3) User-Defined External Tools
  3) 用户定义的外部工具

  4) Project To-Do list
  4) 工程任务列表

  5) Built-In Compiler Flag Configuration
       (although obviously irrelevant if using your own Makefile)
 5) 内置编译器标志配置
    (如果使用你自己的Makefile显然无关)

  6) Very Adaptable Text Editor
 6) 非常适应性强的文本编译器

  7) Importing of Dev-C++, MS Visual Studio,
       or MS Visual C++ projects/workspaces/solutions.
 7) 导入Dev-C++, MS Visual Studio或MS Visual C++的工程、工作空间、解决方案

  8) Additional Code::Blocks Plugins
 8) 附加的Code::Blocks插件

Code::Blocks Messages Pane Thumb
Code::Blocks 信息窗格块

[1] http://www.frozeneskimo.com/electronics/arm-tutorials/adapting-codeblocks-ide-for-arm-development/
[2] http://www.frozeneskimo.com/electronics/arm-tutorials/setting-up-the-arm-gcc-toolchain-on-windows/
[3] OcdRemote程序提供了Eclipse、GDB调试器和Macraigor片上调试设备之间的接口。
  工作关系图: GDB  <-->  OcdRemote  <-->  驱动  <-->  Macraigor JTAG设备  <-->  目标CPU

你可能感兴趣的:(使Code::Blocks适合ARM开发)