Ubuntu12.04 安装eclipse

安装eclipse

第一种是通过Ubuntu自带的程序安装功能安装Eclipse,应用程序 ->Ubtuntu软件中心,搜Eclipse安装即可。

第二种方法是用命令:应用程序->附件->终端 然后输入(中间可能需要你输入密码):
sudo apt-get install eclipse
sudo apt-get install eclipse-pde
sudo apt-get install eclipse-jdt

安装CDT(c/c++插件)

(1)Help------>Install New Software------>在Work with的框框下输入以下地址回车

 http://download.eclipse.org/releases/galileo

选择Collaboration->Mylyn Bridge: C/C++ Development,安装,重启eclipse

(2)同上输入网址后选择 Programming Languages->Eclipse C/C++ Development


切记:(1)(2)顺序有依赖关系,安装顺序不能颠倒。
在安装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.cvs 1.0.400.v201002111343, action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction).
The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not fou nd.
后来google了一下,发现解决办法。
sudo apt-get install eclipse-pde

在装cdt插件,完成~


用Eclipse+CDT开发c/c++项目的时候,怎么能让Eclipse发挥代码自动提示的功能呢?其实也很简单:
打开终端:输入:$ gcc -version
得到类似的:gcc 版本 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
很容易就看到你当前使用的版本了。
启动Eclipse.进入:Windows-->Preferences-->C/C++找到Environment。增加两个变量:
CPLUS_INCLUDE_PATH: /usr/include/c++/4.1.3(我的gcc版本)
C_INCLUDE_PATH: /usr/include
接下来新建一个c project.编写代码的时候,当敲入'.'的时候就会自动弹出可备用的代码。



创建启动快捷方式
$ sudo gedit /usr/share/applications/eclipse.desktop
内容如下:
[Desktop Entry]
Type=Application
Name=Eclipse
Comment=Eclipse Integrated Development Environment
Icon=/usr/lib/eclipse/icon.xpm
Exec=/usr/lib/eclipse/eclipse
Terminal=false
Categories=Development;IDE;Java;


C/C++环境配置

Window - Preferences - C/C++
       1、Appearance,选中Group method definitions in the Outline view
       2、Code Style,代码风格,最好选择为BSD/Allmain,然后按习惯修改一些细节,我建议采用默认就可以.
       3、Editor - Content Assist - Auto-Activation - Delay(ms),原值为500,改为100,则智能提示速度将非常快!
       4、Indexer,清空Files to index up-front的内容,修改Cache limits的值,尽可能大,可以提高速度!
       5. Window - Preferences - General - Editors - Text Editors,选中Show line numbers,设置Print margin column为110
       6. Window - Preferences - General - Workspace,取消Build automatically,选中Save automatically before build
       7. 智能提示功能
            打开终端: $ gcc- v
            查看到gcc 版本 例如 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
            启动Eclipse-->Windows-->Preferences-->C/C++找到Environment.增加两个变量:
                    CPLUS_INCLUDE_PATH: /usr/include/c++/4.1.3(我的gcc版本)
                    C_INCLUDE_PATH: /usr/include

使用 Eclipse CDT 开发 (以C举例,C++类似)

1.点击桌面 Eclipse CDT 启动器,点击菜单 File->New->CProject 新建一个 C 工程:

在弹出的向导对话框中 Project Name 后输入 C 工程名:hello,其它默认,然后点击

Next 按钮,进入下一页面;

取消 Release 选项前的勾号,并点击 Finish 按钮,即新建一个 C 工程。

2.编写源码

(1)生成头文件

点击菜单 File->New->Header File 新建一个头文件 hello.h,其内容如下所示:

#ifndef HELLO_H_
#define HELLO_H_
#include <stdio.h>
void say_hello();
#endif /* HELLO_H_ */
(2)编写hello.c文件
点击菜单File->New->Source File新建一个头文件hello.c,其内容如下所示:
#include "hello.h"
void say_hello()
{
    printf("Hello World! \n");
}
(3)编写 main.c
点击菜单File->New->Source File新建一个头文件main.c,其内容如下所示:
#include "hello.h"
int main()
{
    say_hello();
    return 0;
}

3.编译与运行

点击菜单Project->Build Project或点击工具栏中的“锤子”按钮编译工程;然后使用Run菜单

中的Run或Run As或工具栏中的Run按钮或快捷键Ctrl+F11,即可运行:

Hello World!

4.调试

当然程序不是一编写完毕,就可以通过编译的,需要调试。

(1)设置断点

选中main.c页面,将鼠标放在该页面的左边框上,点击鼠标右键,弹出菜单,选择

Toggle Breakpoint选项,如下图所示:

(2)设置Debug配置信息

然后点击菜单Run->Debug Configurations,弹出如下对话框:

由于本工程无命令行参数,所以不需要进行任何设置,点击Close按钮即可。

(3)Debug

点击菜单Run->Debug或使用快捷键F11进行调试,调试过程中使用快捷键F5进行逐步

调试。



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值