Configure C/C++ develop environment using eclipse for windows

11 篇文章 0 订阅

1.Download Eclipse IDE for C/C++ Developers Official Website


2.Download MinGW:(Minimal GNU for Windows) C/C++ Compiler Platform mingw Official Website:

它是一些头文件和端口库的集合,该集合允许人们在没有第三方动态链接库的情况下使用 GCC(GNU Compiler C)产生 Windows32 程序。

3.Download CDT:C/C++ Development Toolkit Official Website


4.Download GDB: C/C++ Debug Platform  Official Website  install to MinGW home directory.


5.Download MSYS:Official Website

Minimal GNU(POSIX)system on Windows,是一个小型的GNU环境,包括基本的bash,make等等。是Windows下最优秀的GNU环境。

6.Add environment variable

MinGW_HOME such as E:\MinGW

Set  %MinGW_HOME%\bin and%MinGW_HOME%\msys\1.0\bin to PATH

LIBRARY_PATH                %MinGW_HOME%\lib 

C_INCLUDE_PATH         %MinGW_HOME%\include

CPLUS_INCLUDE_PATH      %MinGW_HOME%\lib\gcc\mingw32\4.7.2\include\c++

Rename mingw32-make.exe to make.exe in bin directory.(Because eclipse using make for default,rathan then mingw32-make,so,you can update eclipse setting too.)

7.Validate Setting:

可以在运行栏里输入cmd,进入DOS窗口,输入

mingw32-make.exe -version

如果能出现类似以下信息:
GNU Make 3.82
Built for i386-pc-mingw32
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

就说明ok了,否则检查前面几步操作是否正常

注:mingw是纯绿色软件,本机安装完成以后,如果要在其它机器上安装,只要把本机的mingw目录复制过去就行.


8.Configure Eclipse

For CDT using MinGW, you should configure Eclipse:
Window->Preferences->C/C++->New CDT project wizard->Makefile Project 
find Binary Parser then cancel Elf Parser and select PE Windows Parser.


New Managed Make C project 

Cancel Project -> Build Automatically and build application by "Ctrl+B"

添加一个编译命令

Target Name:MAKE FILE

Builder Command:g++ hello.cpp -g -o run

这里如果是c环境就改成gcc hello.c -g -o run

双击MAKE FILE,此时Eclipse在项目文件的根目录创建一个run.exe的文件,此文件根据hello.cpp代码编译生成。

双击run.exe可以预览效果,控制台输出结果:Hello world!


8. 下面建一个Makefile类型的工程。选择New C++ Project -> Makefile project -> Empty Project, 我们建一个空的项目,建完后里面什么也没有(除了2个.project文件),这时,我们要建一个源文件和一个make文件:main.cpp 和 makefile,如下,都建到根目录下: 
 

C++代码   收藏代码
  1. /* 
  2.  * main.cpp 
  3.  */  
  4.   
  5. #include <iostream>  
  6. using namespace std;  
  7.   
  8. int main () {  
  9.     // Say Hello five times  
  10.     for (int index = 0; index < 5; ++index)  
  11.       cout << "HelloWorld!" << endl;  
  12.     char input = 'i';  
  13.     cout << "To exit, press 'm'" << endl;  
  14.     while(input != 'm') {  
  15.         cin  >> input;  
  16.         cout << "You just entered " << input  
  17.              << " you need to enter m to exit." << endl;  
  18.     }  
  19.     exit(0);  
  20. }  

Makefile代码   收藏代码
  1. all: hello.exe  
  2.   
  3. clean:  
  4.     rm main.o hello.exe  
  5.   
  6. hello.exe: main.o  
  7.     g++ -g -o hello main.o  
  8.   
  9. main.o:  
  10.     g++ -c -g main.cpp  

注意,makefile里的行首缩进用的是Tab而不是空格。如果编译时提示 No separator...就是这里有问题。  

9. Ok, 选中工程,点Build(或点那个小锤子),你会发现这个错误:(Cannot run program "make": Launching failed),啊,我们的make.exe还没设。选中工程,直接Alt-Enter到工程属性页,把msys的bin加到Path里。 
 


2、点右键运行-》launch failed.Binary not found 出错

解决方式:编写程序源文件然后编译ctrl+B,编译所有源文件

然后就产生.o 文件和二进制文件

4.包含外部的.h和库文件(.a)  
        如vs一样,Eclipse添加include 时在 project(项目)-->properties(属性)-->C/C++ Build 
        -->Settings-->GCC C++ Compiler-->Directories-->Include paths (-I) 这里添加路径的 
        添加库文件(也就是VS中的.lib文件在mingw是.a文件) 
        被添加到project(项目)-->properties(属性)-->C/C++ Build 
        -->Settings-->GCC C++ Compiler-->MinGW c++ Linker-->Libraries--->Library search path (-L) 
        这里是添加.a文件的路径 
        而在Libraries(-l) 添加的是.a文件的名称::!!!! 要特别注意比如opengl的库文件时libglut32.a 
        那么你在这里添加的应该是glut32 去掉头部的lib,去掉尾部的.a 这样才是正确的 
5.还有几个要注意的  
      project(项目)-->properties(属性)-->C/C++ Build 
        -->Settings里面的Binary Parsers中如果你是在window下就应该选择 PE windows Parser 
    还有就是我想把exe输出到指定的路径比如说F:/OpenGL, 
       那么你可以再project(项目)-->properties(属性)-->C/C++ Build 
        -->Settings--->Build Artifact 里面的Artifact name 哪里填写它的路径前缀, 
        这里是产生的exe的名字如果里面原本是openglDemo 
        那么编译成功后应该产生一个openglDemo.exe的可运行文件 
       如果你想把这个文件直接输出到F:/OpenGL九可以再这里填写 
        F:/OpenGL/openglDemo 这样写, 
6.还有一个就是运行路径的问题  
如果你Artifact name 设置成F:/OpenGL/openglDemo那么编译成功后, 
运行还要设置一个地方就是运行的位置现在你编译好的项目 
选择菜单的Run--->Run configurations -->点出一个C/C++ Local Application--> 
你要选择正确的Main --> Project : 正确的Main -->c/c++ Application, 
也就是你生成的路径F:/OpenGL/openglDemo.exe 

Arguments --> Working directory:设置你运行的路径F:/OpenGL/ 那么现在运行就成功了


Eclipse/CDT Building Error:( Exec error:The system cannot find the file specified.)

I got this error after reinstalling a fresh OS. It was really frustrating.
It is solved right now. And I dont know how I really make that.

Possible Solutions:
1. Kaspersky prohibits the file org.eclipse.cdt.core.win32_3.1.2.200702150621\os\win32\x86\starter.exe, add it to the trusted zone.

2. Eclipse->window->Preferences->c/c++->Managed Build->Environment
click "New"
Name: Path
Value: (leave the default value and add the mingw/bin path to the end, separated by ;)
Delimiter: ;
Operation: Replace


Eclipse + CDT + MinGW编辑C程序出错误:

dos 命令行中使用 gcc –o hello.exe HelloWord.c可以成功编译运行,可是在eclipse中使用CDTbuild时,总是报错

出现编译错误:

**** Rebuild of configuration Debug for project example ****

**** Internal Builder is used for build               ****
gcc -O0 -g3 -Wall -c -fmessage-length=0 -osrc\demo.o ..\src\demo.c
Internal Builder: Cannot run program "gcc": ?????????¨?
Build error occurred, build is stopped
Time consumed: 0 ms.

 

分析一下失败原因:

1.先把mingw的bin路径加到windows的环境变量中,然后在cmd下,输入gcc -v,显示ggc版本,是可以找到gcc的

2.不能把mingw安装到D盘的Program Files下了,因为路径中,包含空格,而gcc是linux下开发的,对空格默认是分隔符,所以此路径非法,所以找不到gcc

3.eclipse cdt安装 下载的与更新安装有一个比较大的区别,下载时plugins下面有一个jar:org.eclipse.cdt.core.win32_5.0.0.200902130801.jar
拷贝到eclipse 中的要解压成文件夹的型式,并删除原来的jar:org.eclipse.cdt.core.win32_5.0.0.200902130801.jar

在32位windows下不是org.eclipse.cdt.core.win32_5.2.0.201202111925.jar这个文件,而是org.eclipse.cdt.core.win32.x86_5.2.0.201202111925.jar这个文件。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值