Window+GCC+CDT用Eclipse开发C、C++

Window+GCC+CDT用Eclipse开发C、C++

转自:http://www.eclipseworld.org/bbs/read.php?tid=164   中国Eclipse社区 -> Eclipse使用

Eclipse 除了可以开发 Java 之外,还支持了许多语言,现在先介绍
C C++ 的开发环境设定,以后有机会再介绍其它的。 Enjoy it

OS Windows XP Professional SP1
使用版本: Eclipse 2.1.2

. 首先要下载 CDT Eclipse 2.1.2 使用者,请下载这项:
CDT 1.2 Full for Windows R2.1.1 1.2.0 GA - Full - Windows
Eclipse 2.1.3 使用者请下载: CDT 1.2.1
Eclipse 3.0 M7 使用者请下载: CDT 2.0 M7
Eclipse 3.0 M8 使用者请下载: CDT 2.0 M8
Eclipse 3.0 M9 使用者请下载: CDT 2.0 M9
下载网址: http://www.eclipse.org/cdt/

安装:将解压缩后的 features plugins 整个数据夹复制到 Eclipse 安装数据
里,重新开启 Eclipse 即可。

. 下载可在 Windows 上使用的 GNU C C++ 编译器,这里要下载的是: MinGW
Download 页面很长的一串,请选择这个版本:
MinGW bin MinGW-3.1.0-1.exe 14863 kb Sep 15, 2003 11:14
下载网址: http://www.mingw.org/download.shtml

安装:安装目录选 C 槽,然后狂点下一步 (Next) 就行了。安装完后路径是这
->C:/MinGW

. 先在 Command Line 模式下测试编译与执行。先将 C:/MinGW/bin 底下的
mingw32-make.exe 更名为 make.exe ,因为待会在 Eclipse 使用时它预设
会抓系统里 make 这个文件名而不是 mingw32-make

( 注:如果不更名或是还有其它 make 程序时,也可以在稍后的 Eclipse 设定
中,在 make targets view 的地方,新增一个 task 时, build command 取消
use default , 使用 mingw32-make ,或在 project properties->make project ->
make 改为 mingw32-make ) -- snpshu 补充。

在环境变量里加入下列设定:
PATH C:/MinGW/bin; ( 如果系统已经有装其它 C/C++ 编译器,请把 C:/MinGW/bin 加在最前面。 )
LIBRARY_PATH C:/MinGW/lib
C_INCLUDE_PATH C:/MinGW/include
CPLUS_INCLUDE_PATH C:/MinGW/include/c++/3.2.3;C:/MinGW/include/c++/3.2.3/mingw32;
C:/MinGW/include/c++/3.2.3/backward;C:/MinGW/include

先使用文字编辑器编写测试用的原始档,档名: main.cpp
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
 
int main( void ) {
    cout << "Can You Feel My World " ;
 
    return 0;
}

Command Line 下编译指令:
1
C:/g++ main.cpp -O3 -o hello

(O3 O 是英文大写 " ")
编译成功后:便会产生 hello.exe 的执行档。
执行画面如下:
1
2
3
4
5
6
7
8
9
10
Microsoft Windows XP [ 版本 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:/Documents and Settings/Sungo>cd/
 
C:/>g++ main.cpp -O3 -o hello
 
C:/>hello
Can You Feel My World
C:/>

注: -O3 旗标表示采最高级编译最佳化,编译速度最慢,但产生的执行档
档案会最小,执行速度会最快; -o 旗标表示将编译完的 *.exe 重新更名。

步骤一 . 开启 Eclipse 后,首先先开启 C/C++ 专用视景。
Windows->Open Perspective->C/C++ Development

步骤二 . 建立一个 C++ 用的项目。
File-New->Project->C++->Standard Make C++ Project
( 接下来的步骤跟建立一般的 Java 项目一样,皆采预设即可 )

步骤三 . 把我们刚刚写的 main.cpp import 进来,加到专案里。
File->Import->File System-> 浏览 C:/main.cpp

步骤四 . 建立一个 makefile
File->New->File ,文件名称填: makefile ( 不需打扩展名 )

makefile 内容如下:
1
2
all:
    g++ main.cpp -g -o run

注意: makefile 缩排要以 Tab 键作缩排,不能以空格 4 作缩排,
否则 Build 会有问题。

步骤五 . 设定 Make Targets
Windows-Show View->Make Targets
Make Targets 窗口里按鼠标右键, Add Build Target
name 打:编译。 Build Target 打: all

步骤六 . 编译。
在刚刚建立的 Make Targets " 编译 " 上点鼠标 2 下,即会开始编译,
此时我们可以发现 hello.exe 已经产生在我们项目下了。可在底下
C-Build 窗口看到以下输出结果:
1
2
make -k all
g++ main.cpp -g -o run


步骤七 . *.exe 执行前设定。因为在 Windows Run ,所以要先作个设定
,请开启 Project->Properties->C/C++ Make Project->Binary Parser 页面。
Binary Parser 下拉式选单,将 ELF Parser 改成 PE Windows Parser

步骤八 . 执行。
Run->Run as->C Local Application
在底下 Consloe 窗口看到 hello.exe 的执行结果。

注:当原始档有修改,要重新编译时,只要鼠标双击我们在步骤五
所建立的 Make Targets " 编译 " ,即可 Rebuilding

中国Eclipse社区,打造中国最专业的Eclipse开发者社区!!

地址:http://www.eclipseworld.org
[楼 主] | Posted: 2005年10月16日 19:20
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值