Ubuntu下搭建Eclipse的C/C++环境

来源:互联网 发布:姐妹花杀手 网络电影 编辑:程序博客网 时间:2024/05/20 21:21

Ubuntu使用eclipse搭建c/c++编译环境----CDT插件

环境:

Ubuntu  16.04  64bit

目标:

安装并配置CDT环境

具体步骤:

       首先是安装Eclipse,方法有两种:
       第一种是通过Ubuntu自带的程序安装功能安装Eclipse,应用程序->Ubtuntu软件中心,搜Eclipse安装即可。
       第二种方法是用命令:应用程序->附件->终端(Ctrl + Alt + T)
sudo apt-get install eclipse
sudo apt-get install eclipse-pde
sudo apt-get install eclipse-jdt
       使用第一种方法安装时候,在安装CDT插件过程中,有可能会出现下面的错误
       An error occurred while installing the items
       session context was:(profile=PlatformProfile, phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, operand=null --> [R]org.eclipse.ant.ui 3.4.1.v20090901_r351, action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction).
       The artifact file for osgi.bundle,org.eclipse.ant.ui,3.4.1.v20090901_r351 was not found.
       说是eclipse-pde或是eclipse-jdt没安装上。其说明的网址如下:https://bugs.launchpad.net/ubuntu/+source/eclipse/+bug/477944。全英文的。所以,如果使用第一种方法的,最好,再在终端输入命令:
sudo apt-get install eclipse-pde
sudo apt-get install eclipse-jdt

       再安装CDT插件,方法如下:
       1、启动eclipse,
       2、选择Help->Install New Software...,在Work with的框框下复制下面的地址:  http://download.eclipse.org/releases/galileo
       3、选择Collaboration->Mylyn Bridge: C/C++ Development,安装,重启eclipse。
       4、同上述2、3,选择Programming Languages->Eclipse C/C++ Development。重启eclipse。
       注意:
       在安装Mylyn Bridge: C/C++ Development,如果直接选择安装Eclipse C/C++ Development,会出现如下错误:
       Cannot complete the install because one or more required items could not be found.
       Software being installed: Mylyn Bridge: C/C++ Development 5.1.0.200909110608 (org.eclipse.cdt.mylyn.feature.group 5.1.0.200909110608)
       Missing requirement: Mylyn Bridge: C/C++ Development 5.1.0.200909110608   (org.eclipse.cdt.mylyn.feature.group 5.1.0.200909110608) requires 'org.eclipse.mylyn.context.core 3.0.0' but it could not be found

       注意:要记得安装C++必要工具,安装的是GCC工具链,Make等一系列开发工具,命令如下:
sudo apt-get install build-essential
       要不然#include头文件的时候,会出现提示:Unresolved inclusion: 

       好了,Ubuntu下面,安装Eclipse,同时装CDT插件,完美解决了,下面是无意间搜到的一个帖子(CSDN的),有对CDT相关的优化设置。里面说Eclipse的CDT智能编辑相当强大,速度爆快。而其针对代码编辑的易操作性,可能是目前所有C++编辑器里最好用的! 其重构、函数实现,都非常好用。这些是VS(不借助VC助手)和C::B所不能的。 
       帖子地址为:配置Eclipse CDT,支持VC编译器,送分!

       对Eclipse+CDT环境中一些推荐配置重新整理一番,如下:
       
       一、C/C++环境配置:Window - Preferences - C/C++ 
       1、Appearance,选中Group method definitions in the Outline view
       2、 Code Style,通过New来新建一个代码风格,命名为qpsoft,且初始化为BSD/Allmain,然后按习惯修改一些细节。我建议是采用默认的,或许是我过去编Java编写习惯的原因。可按自己的意愿来。
       3、Editor - Content Assist - Auto-Activation - Delay(ms),原值为500,改为100,则智能提示速度将非常快!
       4、Indexer,清空Files to index up-front的内容,修改Cache limits的值,尽可能大,可以提高速度!
       
       二、修改智能提示快捷键:
       Window - Preferences - General - Keys,输入Content,找到Content Assist,在Binding中修改为Shift+Space,要顺手的多。

       三、其他设置
       1. Window - Preferences - General - Editors - Text Editors,选中Show line numbers,设置Print margin column为110
       2. Window - Preferences - General - Workspace,取消Build automatically,选中Save automatically before build

       四、通过插件扩展功能
       1. 支持Subversion:Eclipse官方出品,主页位于http://www.eclipse.org/subversive/。
       在安装时可以通过Help->Install New Software...,在work with框框复制地址:http://download.eclipse.org/technology/subversive/0.7/update-site/   

在编译运行的时候,要一定要先ctr+b编译,然后链接运行,要不然的话会出现,lanch faild,binary not found !

另外需要注意的是我们在编译C++的时候要注意配置编译器的路径和C++运行库的路径,具体方法是打开windows->preference->C/C++->Environment
C_INCLUDE_PATH=/usr/include
C_PLUS_INCLUDE_PATH=/usr/include/c++/4.6.3
其中,/usr/include/c++/4.6.3为gcc编译器的所在路径。


0 0
原创粉丝点击