配置:
1. Eclipse CDT (C/C++ Development Tooling) eclipse CDT 是 Eclipse 插件,它将把 Eclipse 转换为功能强大的 C/C++ IDE。
到http://www.eclipse.org/cdt/downloads.php下载对应版本的CDT
2. Eclipse-> Help->Install New Software->Add
Name 填写 CDT , Location填写下载的CDT位置
勾选CDT Main Features CDT Optional Features
Contact all update sites during install to find required software的√去掉
3. ->Next->Finish, 重启Eclipse ,Help ->About Eclipse, 点选C/C++图标 OK,如看不到C/C++图标,在Eclipse的右上角Quick Access框里输入C,选中C/C++Projects(C/C++)
如果出现:cannot perform operation.Computing alternate solutions,may take a while: ...
可能是有其他插件在线安装或升级造成的,点击 "Available Software Sites",把其他的勾去掉,只保留目前安装的插件,点保存
注意:
1、An error occurred while collecting items to be installed
安装的时候把Contact all update sites during install to find required software的√去掉即可
2、因为Eclipse是Java写的,所以要安装Java的JRE或JDK、编译器要安装MinGW并设置环境变量
启动Eclipse,不同的语言设定不同的工作区,这很 重要,否则很容易配置混淆,造成编译错误。
编译C程序 :
1. 创建c工程:File->New->C Project->Executable,填写Project name ,选择Location,选Empty Project ,MinGW GCC,Finish
2. 工程文件夹右键->New File->File name ->创建.c文件,编辑文件
3. 工程文件夹右键->Build Project
4. Window->Perspective->Open Perspective->Other...->C/C++
5. Run as ->local C/C++ Application
编译C++程序:
1. File->New->Project->C++ Project->next,填写 Project name,Executable 选 Hello World C++ Project ,Toolchains 选 MinGW GCC,Finish
2. 工程文件夹右键->Build Project ,如出现编译错误,工程文件夹右键->Properties,修改Tool Chain Editor
3. Run as ->local C/C++ Application
让eclipse CDT支持C++11
需要在CDT设置如下:
1、菜单:
Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build-in Compiler Settings
添加 -std=c++11
2、右键项目属性:
Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Dialect
添加 -std=c++11 到 other dialect flags 或者列表里面选择 ISO C++11
3、右键项目属性:
Properties -> C/C++ General -> Preprocessor Include Paths, Marcos etc. -> Providers
使 CDT GCC Build-in Compiler Settings 优先 Contributed PathEntry Containers
4、菜单里面选择 Project -> C/C++ Index 重建索引
Eclipse 设置:
1. window--preferences--general--workspace-->text file encoding--other:utf-8//解码
2. window--preferences--general--appearance--theme:dark //黑色主题
3. window--preferences--general--appearance--colors and fonts
-->basic--text font--14//字体
4. window--show view--navigator//导航