2010年8月5日 星期四

Codeblocks Setup with GCC 4.5.0



1. 下載 TDM's GCC 4.5.0




  • 第一次安裝時選擇 Create


  • 若是 32 bit 電腦,選擇 MinGW/TDM (32-bit)


  • 選擇安裝路徑,建議不要用預設的。我安裝在 c:\dev\MinGW32 目錄下。


  • 選擇下載點 (我選的是台灣中央大學 應該吧...XD)


  • 選擇安裝元件,一般預設值就可以了。若要編譯 ada 、 objc 等,就要在 gcc 選項勾選相關的元件。


  • 安裝完後,會有 README 文件,可以看一看。裡面有此版本要注意的事項說明。





2. 安裝 codeblocks


  • 選擇 codeblocks-10.05-setup.exe 版本 (mingw 在第一步驟中已經裝了,codeblocks 包含的 mingw 是 GCC 3.4.5 版)


  • 選擇元件 (全選就對了 XD)


  • 設定安裝目錄,我設在 c:\dev\CodeBlocks


  • 若安裝了 TDM's GCC 4.5.0,codeblocks 會自動偵測 (否則就要手動設定 toolchain 有點麻煩)


  • 接下來開始使用 Codeblocks 啦 (簡稱 CB),首先開啟一個 Console Application


  • 為專案配置目錄



  • 把這段 code 貼上 (測試 C++0x 的 Lambda expression 功能)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
vector<string> v;
v.push_back("Be");
v.push_back("whatever");
v.push_back("you");
v.push_back("want");
v.push_back("to");
v.push_back("be.");
sort(v.begin(),v.end(),[](const string& lhs,const string& rhs){
return lhs.size() < rhs.size();
}
);
return 0;
}



  • 按下 Build,這時候會有 error ,不過錯誤訊息會提醒你要勾選 Compiler 選項 -std=c++0x


  • 那就照著做吧!! Setting -> Compiler and Debugger


  • 接下來在 Build 就可以成功了。


Scott Meyers 這篇 blog 介紹了 GCC 4.5 的更新特色,可以參考
http://scottmeyers.blogspot.com/2010/07/updated-c0x-feature-availability.html

Enjoy It ~ \( ̄︶ ̄)>

沒有留言:

張貼留言