Windows下MinGW与Eclipse CDT开发环境搭建(转)

开发环境:eclipse-cpp-galileo-win32、MinGW5.1.6

1、下载Eclipse for cpp
到Eclipse的官方网站http://www.eclipse.org上下载Eclipse cpp edition。
我下载的是eclipse-cpp-galileo-win32.zip,解压后就可以运行,当然还不能进行开发,需要配置编译器

2、安装MinGW
现在我们需要在Windows上安装和配置C/C++的编译器。在Windows下我们可以选择Cywin工具箱或者MinGW(Minimalist GNU for Windows)。Cywin在安装时不是很友好,所以我邓MinGW,到MinGW网站http://mingw.sourceforge.net上,下载MinGW,安装,选择要安装的compiler,然后选择download and install,很快就可以装完。

3.安装GDB Debugger,在http://nchc.dl.sourceforge.net/sourceforge/mingw可以下载到gdb的最新版本,然后解压到之前安装MinGW的目录。

4、添加环境变量
右键我的电脑->属性->高级->环境变量->系统变量中添加
MINGW_HOME=D:/Dev/MinGW(你的安装路径)
在PATH变量的最后增加 ;%MINGW_HOME%/bin
LIBRARY_PATH = %MINGW_HOME%/lib
C_INCLUDE_PATH = %MINGW_HOME%/include
CPLUS_INCLUDE_PATH = %MINGW_HOME%/include/c++/3.4.5;%MINGW_HOME%/include/c++/3.4.5/mingw32;%MINGW_HOME%/include/c++/3.4.5/backward;%MINGW_HOME%/include

5、在Eclipse中配置MinGW
因为Eclipse预设用来编译的文件为 make.exe 但是 MinGw 安装后 make 的文件名是 mingw32-make.exe,因此可以把mingw中的 mingw32-make 改名为 make,或者在相应工程的Project->Properties->C/C++ make project
   build command 的“make”改为“mingw32-make”,再按“apply” “OK” 。

至此,就可以在windows下面使用Eclipse进行C/C++程序开发了

 

以下为个人实践:

先从eclipse.org网站上下载一个集成了cdt的eclipse;我下的版本是eclipse-cpp-helios-win32.zip,解压后就能直接使用,但是使用时要求安装了JRE(JAVA RUNTIME ENVIROMENT),于是下载了一个jdk6版本:jdk-6u20-windows-i586.zip;安装完成JDK后设置环境变量:

在PATH变量的最后增加 C:/Program Files/Java/jdk1.6.0_20/bin(我的安装路径)

classpath=.;C:/Program Files/Java/jre6/lib;

然后下载一个DEV-C5的c/c++编译工具,我下的版本是WY_DEVCPP_5B0905.zip;下载完成后安装,安装这个编译器主要是因为安装完成后得到的文件跟安装MINGW所得到的大致相同;后面就是根据上面的第四步设置环境变量。而上面的第五步由于安装的是dev-c,make的文件名就已经是make.exe了,所以可以省去第五步。

经过上面的步骤后,已经能使用在windows下使用eclipse开发c/c++程序了。这样完成后的开发环境在eclipse中不能调试,后面下了个6.8版本的GDB覆盖dev-c带的gdb.exe,问题得以解决。

然而接下来的问题是eclipse中printf没有输出问题:

Ask:

The eclipse console has weird behaviour when used for input with C programs.
I teach C to first year undergraduates and I want them to learn their way through eclipse. But the small silly programs that ask you to input characters have weird behaviour, if you use the eclipse console. It seems like it groups all input and output commands and executes them together...for example... the following program:

#include <stdio.h>

int main(void) {

         int n = 0;

         printf("Gimme a number: ");

         scanf("%d", &n);

         printf("/nThe number you entered was %d/n", n);

         return 0;

}

 

has the following output:

4

Gimme a number: The number you entered was 4

Pretty normal output on any console you'll find, not just with eclipse's one instead of

Gimme a number: 4

The number you entered was 4

 

Answer:

To obtain this output, you have to flush stdout before scanf'ing the number. The output is flushed either implicitely when a newline character is echoed on the console (printf("/n")) or explicitely with fflush(stdout);

 

ps: printf() 语句将输出传递给缓冲区的中介存储区,然后缓冲区的内容再不断地被传递给屏幕,C标准规定,有3种情况会将缓冲区的内容传递给屏幕:缓冲区满的时候,需要输入的时候以及遇到换行符。所以说a newline character is echoed on the console,早期的c语言经常这样做的,例如:

printf(“Hello/n”);

scanf(…..);

不过在eclipse中只能使用ffush( stdout )。将缓冲区的内容传递给屏幕或文件就叫做刷新缓冲区(flushing the buffer)』

 

to get the output you wanted use this program :

#include <stdio.h>

int main(void) {

         int n = 0;

         printf("Gimme a number: ");

         fflush(stdout);

         scanf("%d", &n);

         printf("/nThe number you entered was %d/n", n);

         return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值