ubuntu 安装code blocks全记录

来源:互联网 发布:浴缸推荐 知乎 编辑:程序博客网 时间:2024/05/17 07:25

ubuntu 安装code blocks全记录

 

(一)安装步骤:


1.先把编译环境,C库、C++库和Boost库装好,如下:

sudo apt-get install build-essential
* 有可能安装 build-essential 后gdb就已经安装过了
   sudo apt-get install gdb

2. 在 Ubuntu 软件中心 中安装 Code::Blocks IDE3. 安装 Code::Blocks 的调试组件 Valgrind 用来探测内存泄露的:

 

sudo apt-get install valgrind

4. 安装外围爱好者根据需要自行编译并贡献的软件
sudo apt-get install codeblocks-contrib

5. 安装 wxWidgets 开发相关项:(注:安装前到
www.wxWidgets.org上看一下最新版本)

 sudo apt-get install libwx*.deb

sudo apt-get install libwxbase2.8-dbg
sudo apt-get install libwxbase2.8-dev

sudo apt-get install libwxgtk2.8-dbg
sudo apt-get install libwxgtk2.8-dev 

sudo apt-get install wx2.8-i18n

sudo apt-get install wx2.8-doc
sudo apt-get install wx2.8-examples

sudo apt-get install wx-common

开始使用Code::Blocks了,应用程序->编程->Code::Blocks IDE。

Code::Blocks和wxWidgets整合非常好,几乎不用做任何额外的配置。

第5的另一描述:

添加软件更新源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo gedit /etc/apt/sources.list



# 添加如下两个更新地址
deb http://apt.tt-solutions.com/ubuntu/
edgy main

deb http://apt.tt-solutions.com/ubuntu/
feisty main
sudo apt-get update
sudo apt-get dist-upgrade

然后存盘,退出gedit。

5.安装公钥
wget -q http://apt.wxwidgets.org/key.asc -O- | sudo apt-key add -
wget -q http://lgp203.free.fr/public.key -O- | sudo apt-key add -

从tt-solutions.com添加key
wget http://www.tt-solutions.com/vz/key.asc
sudo apt-key add key.asc

6.安装Code::Blocks最新版和wxWidgets:(注:安装前到www.wxWidgets.org上看一下最新版本)

sudo apt-get install libwxbase2.8-0libwxbase2.8-dbg libwxbase2.8-dev libwxgtk2.8-0 libwxgtk2.8-dbglibwxgtk2.8-dev wx2.8-doc wx2.8-examples wx2.8-headers wx2.8-i18nwx-common

sudo apt-get install codeblocks codeblocks-contrib libcodeblocks0 libwxsmithlib0

开始使用Code::Blocks了,应用程序->编程->Code::Blocks IDE。

Code::Blocks和wxWidgets整合非常好,几乎不用做任何额外的配置。

原因

首先安装wxwidget ,根据codeblocks官网说法,ubuntu 提供的wxwidget版本并非标准版,不能用于codeblocks,原文如下:
----------------------------------------------------------------------------------------------------------------------------------
Important note for Ubuntu users: To be able to use the Debian packages on Ubuntu Karmic Koala (9.10) and Lucid Lynx (10.04) you have to use the wxWidgets packages from apt.wxwidgets.org, because the packages provided by Ubuntu are not compatible with the ones from wxwidgets.org. Alternatively you can use the Ubuntu repo provided by our user pasgui.
------------------------------------------------------------------------------------------------------------------------------------
安装wxwidget的方法:参考链接 http://wiki.wxpython.org/InstallingOnUbuntuOrDebian
大概步骤:
1.先进入“系统”--》“系统管理”--》“新立德软件包管理器“,搜索curl,双击选中,之后点“应用” 如下图:
图片
2.关闭“新立德软件包管理器“,打开:应用程序”--》“附件”--》“终端”
输入 :
curl http://apt.wxwidgets.org/key.asc | sudo apt-key add -

回车。
3.进入“系统”--》“系统管理”--》“软件源”
切到“其他软件”标签,点添加 ,分别添加下面2个链接:
deb http://apt.wxwidgets.org/ lucid-wx main

deb-src http://apt.wxwidgets.org/ lucid-wx main

参考图:
图片

关闭
4. 打开”应用程序关闭
4. 打开”应用程序“--》”附件“--》”终端“ ,执行以下命令:
sudo apt-get update
sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n
5. 现在开始安装codeblocks10 ,从 http://www.codeblocks.org/downloads/26 下载codeblocks
这里选择linux版本 :codebl关闭
4. 打开”应用程序“--》”附件“--》”终端“ ,执行以下命令:
sudo apt-get update
sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n

5. 现在开始安装codeblocks10 ,从 http://www.codeblocks.org/downloads/26 下载codeblocks
这里选择linux版本 :codeblocks-10.05-1-debian-i386.tar.bz2ocks-10.05-1-debian-i386.tar.bz2“--》”附件“--》”终端“ ,执行以下命令:
sudo apt-get update
sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n
5. 现在开始安装codeblocks10 ,从 http://www.codeblocks.org/downloads/26 下载codeblocks
这里选择linux版本 :codeblocks-10.05-1-debian-i386.tar.bz2
图片
(至于下面的codeblocks-10.05-1-debian-dbg-i386.tar.bz2,我没有试过,应该也可以)
6. 解压下载的文件,得到很多.deb文件
7.进入i386文件目录,打开”终端“,执行sudo dpkg -i *.deb
完成后,可在”应用程序“--》”编程“中找到
图片可以到
http://user.qzone.qq.com/7398904/blog/1283250652看。


使用说明:

Ubuntu下CodeBlocks更改调试终端
  
在环境设置里进行如下设置:

把Terminal to launch console programs那个选项改成gnome-terminal -t $TITLE -x

原来是xterm -T $TITLE -e

gnome-terminal和xterm的参数表示方法不一样。


汉化方法:

/usr/share/codeblocks/新建locale文件夹然后把 codeblocks.mo 拷贝到locale文件夹内。重现启动codeblocks 自动转换为中文界面。
下载地址:
http://forum.ubuntu.org.cn/download/file.php?id=56568

1.可以自己写Makefile:

 在Project的属性中指定使用custom makefile即可。和visual studio一样,可以定义很多编译和link过程中的参数,包括定义编译参数等,这些都可以在Project的build option或compiler/debugger settings中找到。
 对于一些使用autoconf/automake的项目来说,我想只有新建一个project,然后将源码导入才行。不过,现在已经有人开始做autoconf/automake的code blocks的plugin了。

2.可以定义快捷键:

 遗憾的是,只能给菜单中出现的项目定义快捷键,对于比如editor中右键弹出的context menu中的项目无法定义快捷键。
 Settings -> Editor -> Keybord shortcut里面可以定义快捷键。
 注:[Edit]->[Complete code]的快捷键Ctrl - Space(与输入法冲突)要改成Ctrl - k
   (不限为Ctrl -k,只要不冲突,任用你喜欢的键)。

 management, log, message panel等都不能autoshow/autohide。要么关闭,要么显式。也不能dock成一条,吸附在屏幕两边。对于这个问题,我使用的办法是:给display/hide这些pane定义快捷键,使用这些快捷键来显式或隐藏这些pane,效果也不错。

3.定制F1帮助系统
 在Settings -> Environment -> Help files中新建一个entry,名为man,接着的对话框选no,然后手动在下面的path中填写: man:/usr/share/man 
 将default (使用F1快捷键)勾上。这样就可以使用manpage了。在editor中,将光标停在想要查询的内容上面,按F1,就会弹出一个panel,里面就有查询内容的man手册,非常的方便。比如printf,按F1,弹出的panel中就显示printf的man手册。
在 [终端] 下执行下行语句,安装GNU C标准
sudo apt-get install manpages-dev          // C API 
sudo apt-get install manpages-posix        // posix function
sudo apt-get install manpages-posix-dev // posix develop documents
sudo apt-get install glibc-doc                   // C API
sudo apt-get install stl-manual                 // STL
sudo apt-get install libstdc++6-4.1-doc    // 注:我写这篇文章时,安4.1这个man std::string可以
sudo apt-get install libstdc++6-4.3-doc    // C++ API,建议先安这个试,再试4.1
sudo apt-get install manpages-zh            // 中文文档
修改man默认的语言
sudo gedit /etc/manpath.config
把里面所有含 /usr/share/man 的行拷贝添加到其下一行并改成 /usr/share/man/zh_CN
中文在上,英文在下,如下所示:
(注:以MANDB_MAP开头的就不要改了不然会有如下错误提示的
           man: 无法解析 /usr/share/man/zh_CN/man3/std::vector.3.gz: 没有该文件或目录)
MANDATORY_MANPATH /usr/share/man/zh_CN

MANPATH_MAP /bin /usr/share/man/zh_CN
MANPATH_MAP /bin /usr/share/man
MANPATH_MAP /usr/bin /usr/share/man/zh_CN
MANPATH_MAP /usr/bin /usr/share/man
MANPATH_MAP /sbin /usr/share/man/zh_CN
MANPATH_MAP /sbin /usr/share/man
MANPATH_MAP /usr/sbin /usr/share/man/zh_CN
MANPATH_MAP /usr/sbin /usr/share/man
MANPATH_MAP /usr/games /usr/share/man/zh_CN
MANPATH_MAP /usr/games /usr/share/man
保存后退出

4.自动补全功能设置
  每个新建工程都要在菜单[Project] -> [Properties...] -> [C/C++ parser options]中添入头文件所在目录,这样自动补全与信息提示功能才可正常工作,如下是标准库头文件的目录:
/usr/include
/usr/include/bits
/usr/include/c++/4.3/tr1
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.3/include
/usr/lib/gcc/i486-linux-gnu/4.3.3/include
下面这个是socket的文件路径
/usr/include/sys
/usr/include/netinet
/usr/include/arpa
添上后不是立即起效,过一段时间后你就发现功能突然出现!

5. 修改 GNU ARM GCC Compiler
1. [Settings] -> [Compiler and debugger settings]
    将Setected compiler 修改为GNU ARM GCC 编译器。


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 自带的即可!

6. 智能化配置:
一、[Settings] -> [Editor...] -> "Code-completion and symbols browser"中
1. 将 Keyword sets to additionally include 中1到9都勾上,
    1 ~ 9 对应的关键字可在 "Syntax highlighting" 的 [keywords...]按钮 中设置,
    默认其中 1 是 C++ 关键字,3 是 Doxygen 关键字;
2. 将 Delay for auto-kick-in when typing [.::->] 拉到 200ms,这样快点出来提示
3. 将 Automatically launch when typed # letters 中的4改成2,这样打两个字母就会有提示了
4. 将 Case-sensitive match 的勾去掉,它会帮你纠正大小写

二、[Settings] -> [Editor...] -> “Abbreviation” 中
定义了许多缩写(还可以自定义),只要输入这些缩写,并按Ctrl+J,就可以自动完成常用的代码框架,并可将光标放在恰当的地方(自定义时用|表达),常用的有:guard、class、switch等。

7. 快捷键:
Ctrl + 滚轮          代码的字体会随你心意变大变小

右键 + 拖动鼠标    省得去拉(尤其是横向)滚动条,相关设置:Mouse Drag Scrolling

Atl + 拖动鼠标      实现部分选择(只选中区域内的字符,而不会包含它们所在行的其他字符)。
Ctrl+D                可复制当前行或选中块
Ctrl + 拖动鼠标    复制到新位置

Ctrl+Shift+C       注释掉当前行或选中块
Ctrl+Shift+X       解除注释

Tab                      缩进当前行或选中块
Shift + Tab          减少缩进

F2                        显隐下方Logs & others栏
Shift+F2              显隐左方的Management栏

Ctrl+G                   到达指定行
ALT+G                  到达指定文件
Ctrl+Alt+G            到达指定函数(支持头文件中的函数定义)
F11                       切换源文件与头文件

Ctrl + PageUp        到达上一个函数
Ctrl + PageDown   到达下一个函数。

Ctrl + B                  添加书签
Alt + PageUp 和
Alt + PageDown    可以切换书签

Ctrl + Shift + B      可找到匹配的括号。

8. 备份~/codeblocks/Default.conf,就不会丢失你的配置:
在终端里执行 cb_share_config 这个命令,会打开如下窗口:

(二)安装svn版

(尽量不用,因为可能产生依赖错误,这个困扰我很久)


翻译:执行命令

1.sudo add-apt-repository ppa:simger/codeblocks

2.sudo apt-get update

3.检查更新。

写此文时可更新为svn6203,并且在http://apt.jenslody.de/ 已提供了codeblocks最新正式版10.05

英文原文:https://launchpad.net/~simger/+archive/codeblocks

PPA description

This PPA provides Ubuntu rebuilds of "Jens' unofficial debian-repository for Code::Blocks" (http://apt.jenslody.de/ )

Adding this PPA to your system

You can update your system with unsupported packages from this untrusted PPA by adding ppa:simger/codeblocks  to your system's Software Sources. (Read about installing )

Technical details about this PPA

(三)更新codeblocks 10.05


安装批量deb命令:sudo dpkg -i *.deb 
安装后会出现依赖错误,以下是解决办法:

Installing wxWidgets and wxPython On Ubuntu Or Debian

There are wxWidgets and wxPython packages in the standard software repositories for Debian and Ubuntu, but they are usually at least a few releases behind the current release, and in some cases many releases behind. Since many users prefer to use only packages installed from repositories (for easier package management) but still would like to have newest versions possible of their installed software, we have our own APT repository that is usually updated within a few days of each release. To use it to be able to keep your wx on the cutting edge release just follow these instructions.

  1. The packages and the repository meta-data are digitally signed, so you'll need to import the key into your apt's list of trusted keys in order to not get warnings about it.
        curl http://apt.wxwidgets.org/key.asc | sudo apt-key add - 
  2. Add the following lines to your /etc/apt/sources.list file (or use the "software sources" program under the "system" menu).Replace the "DIST" text with whatever is appropriate for your system. (See the table below for a list of supported distributions and architectures.)

        # wxWidgets/wxPython repository at apt.wxwidgets.org
    deb http://apt.wxwidgets.org/ DIST-wx main
    deb-src http://apt.wxwidgets.org/ DIST-wx main
    For example, if your distro is Ubuntu Gutsy, then you would use the following configuration statements:

     

        # wxWidgets/wxPython repository at apt.wxwidgets.org
    deb http://apt.wxwidgets.org/ gutsy-wx main
    deb-src http://apt.wxwidgets.org/ gutsy-wx main
  3. Run the this command to update your local copy of the package meta-data.
        sudo apt-get update  
  4. You can now use your favorite package selection tool to install or upgrade the wxWidgets and wxPython packages. Here's how to do it with apt-get:

        sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18nThe packages libwxgtk2.8-dev and libgtk2.0-dev may need to be installed if a 3rd party application requires wxWidgets when building from source.

     

        sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n libwxgtk2.8-dev libgtk2.0-devThese packages (and their dependencies) will replace earlier versions of wxPython and wxGTK in the same ReleaseSeriesthat may have been installed previously. There are a few other wx packages as well, but those listed above and their dependencies are the core that are needed for use with wxPython.