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 IDE 3. 安裝 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-0
libwxbase2.8-dbg libwxbase2.8-dev libwxgtk2.8-0 libwxgtk2.8-dbg
libwxgtk2.8-dev wx2.8-doc wx2.8-examples wx2.8-headers wx2.8-i18n
wx-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 )