Personally, I am NOT a fan of Integrated Development Environments
(IDEs). They take up too much space on the screen; they tend to be slow
to load; and worst of all, most of them force me to use their
text editor, rather than the one I use for everything, Vim. That latter point is important to me; over the
years I've built up a number of shortcuts in my Vim startup file which
save me typing, and I use Vim for everything I do--programming, word
proceessing, Web development, e-mail and so on. (But see the comment on
the Vim plugin for Eclipse below.)
Having said that, though, if I were to use any IDE, Eclipse
would be the one.
Eclipse is a framework for IDEs. I say "framework,"
because it provides the infrastructure for the IDE, and then the IDE is
completed by using a plugin for a particular programming language.
Plug-ins exist for Java (which was its first application), C/C++,
Python, Perl and many others.
Moreover, I actually can still use Vim, as an Eclipse
plugin exists for it, called vimplugin.
Eclipse is multi-platform, runnable on Linux, Windows
(Cygwin or MinGW needed in the C/C++ case), etc.
Eclipse came out of the Websphere project at IBM. (See
IBM interview.) Though the Eclipse project is now
fully open-source, it is still strongly supported by IBM. It has been
pointed out that basically Eclipse is a $40 million
gift to the open-source world.
For a quick introduction to Eclipse, do the following:
if Eclipse is not already on your machine, then
obtain and install it, by following the instructions in our sections
below, How to Obtain and Install Eclipse
Eclipse is a very nice piece of software, enjoyable
to use once you get the hang of it. However, beginners
beware--Eclipse can be pretty unforgiving if you don't
issue commands in the desired sequence. Just be patient with this, and
you will be rewarded.
You need to have Java installed, which you almost certainly do already.
However, if you only have GNU Java, you should consider downloading Sun
Java, as Eclipse will run much faster with it. To obtain Sun Java in
Ubuntu Linux, type
sudo apt-get install sun-java6-jdk
You can use apt-get in Ubuntu or yum
in Fedora Linux to get Eclipse too, but you are likely to get an older
version this way. The tutorial here assumes at least Eclipse 3.3, which
differs from earlier versions. So, I recommend manual download and install:
You can download the package from Eclipse's home page. Then do the following:
unzip the .zip file that was downloaded; a
directory/folder anamed eclipse will be created
move that directory to a convenient location; in my case on my
Linux machine, I did
A perspective is the environment under which your
Eclipse screen is currently operating. Roughly
speaking, there is a different perspective for each language, i.e. a
C/C++ perspective, a Java perspective, a Python perspective and so on.
There is also a debug perspective, or more precisely speaking, one for
each language perspective.
The perspectives are plugin packages, which you typically download
separately from Eclipse.
You can go to a new perspective by selecting Window | Open
Perspective and making your choice, or more rapidly, by
choosing it from the right end of the Eclipse top
toolbar if it appears there, or by clicking the Open a
Perspective icon in that same
location.
A perspective consists of a number of tabbed subwindows,
called views.
For example, for C/C++ code, you would be in the
C/C++ perspective, while editing and running your code.
You'd have a navigator view listing your various C/C++ projects
(more on this below), an editor view for each file you currently are
editing, an Outline view showing each of the major
components of your code (functions, global variables, etc.), a
Console view in which standard input/output would be
done, and so on. During your work on your C/C++ code, you would
occasionally use the debugger, in which case you would temporarily
switch to the Debug perspective, which would have a
number of views as well.
Most language perspectives include a navigator view, listing projects.
For C/C++, it is called C/C++, for Python it is the
Pydev Package Explorer, in Java it's simply the
Package Explorer and so on. Or you can always go to
the generic navigator view, called Navigator.
The view of a view, no pun intended, is often cramped. To enlarge
it, you can drag its border horizontally or vertically. Or click on the
Maximize icon; it becomes a Restore
icon which you can use to return to the default (cramped) mode.
If a view is no longer on your screen, you can retrieve it by
selecting Window | Show View and then clicking on the
view name.
If within a perspective you wish to reset the views to their
original configurations, select Window | Reset Perspective.
Following are the steps for creating, developing and debugging a
project. Note that in some cases there are special details for your
particular language, which you must check in the "Special Details"
section below for that language.
make a project (or choose an existing one); see "Projects" below
create your source files with the Eclipse editor,
or copy them from non-Eclipse files on your systtem;
see "Editing Files" and "Importing
Files" below
build (i.e. compile) your project, if appropriate for the language
if there are any syntax errors, they'll show up in
Console view, in the editor view etc.; you can click on
a problem and you will be taken to the relevant source line in the
editor view
the first time you run/debug your program, you will need run
and debug configurations; these specify the name of your executable
(and in what project), its command-line arguments if any, its special
shell variable environment if any, your debugger of choice, and so on;
make SURE to create BOTH run and debug configurations, IN THAT
ORDER:
create your run configuration:
select Run | Open Run Dialog
right-click the entry for your language, for instance C/C++
Local Applications, and select New
fill in Name with a configuration name of your
choice (here and in some steps below, Eclipse may do this
automatically for you)
select the Main tab, and fill in your run
configuration (Name), project and executable file
names
if you have command-line arguments or special environment
variables, click the Arguments or
Environment tab, and fill in the desired
settings
hit Apply and Close to
complete creation of your run configuration
create your debug configuration:
start creating your debug configuration, by selecting
Run | Open Debug Dialog
Eclipse may fill in the various of pieces of
information for you, based on your run configuration; if not, fill
them in
hit Apply if asked, and then hit
Close to complete creation of your debug
configuration
from now on, whenever you want to run or debug your code:
keep in mind that run and debug different,
meaning to run outside or within the debugger, respectively
to run:
to run the first time, select Run | Open Run Dialog
, select the run configuration you created above, then
hit Run
for subsequent runs, simply hit Run | Run,
which will run your last launched run, i.e. the one in your run
configuration
to debug:
to debug the first time, select Run | Open Debug
Dialog , select the debug configuration you created
above, then hit Debug
for subsequent debugs, either hit Run |
Debug or click on the Debug icon in the
Eclipse toolbar; this will run your last launched
debug, i.e. the one in your debug configuration
make sure you have the CDT plugin installed, by
clicking Window | Open Perspective and checking to see
that C/C++ is on the list; you may need to select
Other and click on the right arrow next to "C/C++"; if
CDT is not there, see our section on Plugin Installation
when opening a new run/debug dialog, right-click on C/C++
Local Applications (or if the program will run externally to
Eclipse, as with Curses programs, choose
C/C++ Attach to Local Application) and choose
New
and check Connect process input and output to a
terminal if you have terminal I/O
to compile:
a makefile was automatically created for you at the time you set
up the project, in the Debug directory for your
project; if you need to add something, e.g. -l
library linking, right-click on your project name, and select
Properties; point the triangle next to C/C++ Build
downward; select Settings | Tool Settings; point the
triangle next to GCC C Linker downward and select
Libraries | Add (the latter is the green + icon);
and fill in your library flags minus the -l, e.g.
filling in m for -lm
install the Pydev plugin; if you wish automatic installation, go to
http://www.fabioz.com/pydev/updates;
I recommend that you not ask for the optional extensions, as they
require mylin; if you have troubles, download from Sourceforge
configure Pydev to use your choice of the Python or Jython
interpreters, by selecting Window | Preferences ,
pointing the triangle next to Pydev downward, then
selecting your interpreter; you also must state the full path name for
the interpreter, e.g. /usr/bin/python; you may be
asked for directories for libraries, and you might as well choose them
all; then hit Apply and OK
Pydev Package Explorer is your navigator
perspective
in creating a new project, choose the Pydev Project
subheading under Pydev
in creating (or importing) source files, note whether you have a
src directory within your project directory (point the
arrow next to your project name in the navigator downward to check); if
you do, click on src instead of the project name before
creating/importing a source file
no permanent byte code files are created, so there is no build procedure
in setting up a run dialog, note the following:
fill in Main Module with the name of your
source file in which you wish execution to start
in the Arguments tab, fill in Base
Directory to be the one in which you have input files (or
the root of a tree of such directories), and put your command-line
arguments in Program Arguments
in the Debug perspective, the values of the
variables are accessible only in the Variables view,
and only for local variables
you'll definitely need to install PadWalker; the
following is the Unix-oriented version; download the source code
package,
PadWalker-1.5.tar.gz; unpack it in some directory, go to the new
subdirectory that is created by the unpacking, and run
perl Makefile.PL
make
make install
OK, now that you have PadWalker installed, get the EPIC
plugin
use Navigator as your navigator view
there is no build phase, as Perl does not produce byte code
in setting up a run/debug configuration, in the Working
Directory section of the Arguments tab,
uncheck Use Default Working Directory and fill in the
the name of the directory in which you have input files (or the root of
a tree of such directories), and put your command-line arguments in
Program Arguments
in the Debug perspective:
a breakpoint will be automatically set at your first executable
statement
the values of the variables are accessible only in the
Variables view, and only for local variables; you'll
need to use the Perl my keyword in the first
instance of each variable in your source code in order to see the
globals (this is where the PadWalker package
comes in)
make sure you have the Java Development tools
(JDT) plugin installed, by clicking Window | Open
Perspective and checking to see that Java is
on the list; you may need to select Other; if
Java is not there, download JDT,
following the directions in our section on Plugin
Installation
when creating your project, check Use Project Folder As
Root for Sources and Classes
source files will be compiled as soon as they are saved (or
imported), so there is no explicit build step
when you create a run dialog, right-click on Java
Application and select New; in the space
labeled Main Class, fill in the class in which
main() is defined
in debug runs, Eclipse will stop beforemain(); just hit the Resume button
As with many IDEs, Eclipse organizes things into
projects. A project is a directory within your workspace, which
if you took the default when you installed Eclipse is
the workspace directory within your
Eclipse directory, e.g.
/usr/share/eclipse/workspace or
$HOME/workspace.
To create a new project:
this assumes you are using Eclipse 3.3; other
versions may be slightly different, but you should be able to adapt what
you see here
select File | New | Project
select your language (you may need to click to triangle to make it
point downward instead of rightward)
fill in a project name
if you are writing in C/C++, select Executable
select Finish
To go to a project, either previously existing or one you just created:
You can double-click the project name in the navigator view.
If you don't see the panel, switch to the perspective for your language.
If you wish to create a new file that is a copy of one outside your
current project, import it, using the Import command
described below. To create a new file using Eclipse's editor, or to edit
an existing one, read the following.
Eclipse attempts to find an editor related to your file
type (.c, .py etc.), possibly part of
the plugin for the language you're working in. It use syntax
highlighting and perform other actions tailored to your file type.
To make a new file:
right-click on the project name, then select File | New |
Source File for C/C++, File | New | File for
Python or Java, File | New | Perl File for Perl, etc.
make sure that the project name in Source Folder
is correct; enter your new file name; hit Finish
the editor will now open a view for editing
z.c; it will also show your file under your project
name
To edit an existing file:
go to Navigator (or C/C++
Projects, if doing C/C++)
if the files don't appear, click on the arrow next to the project
name
double-click on the file you want
To save your edited file, either right-click the file display and select
Save, or use the keyboard shortcut ctrl-s.
Noteworthy editing operations:
copy-and-paste: on Linux, this seems to work with the usual mouse
actions, i.e. highlight by dragging the left mouse button, then paste
using the middle button; on other platforms, you may need to highlight
then do Edit | Copy and Edit |
Paste
indenting/de-indenting: drag the mouse to highlight the lines of
text to be moved right or left, then select Edit | Shift
Right/Left; the default amount of space indented/de-indented can be
configured by selecting Window | Preferences and then
selecting the language
if you move the mouse pointer to an instance of a variable or a
function call, Eclipse will pop up a window showing you the definition
of that item
the editor will probably have some language-specific convenience
features; for instance, for C/C++, if you highlight some lines of source
code, right-click within the editor window, then choose
Comment, then those lines will be commented out
You can importing files from another directory into your current
project, as follows:
File | Import
Make sure the triangle next to General is pointing
downward, choose File system and hit
Next
select Browse to get to the directory that
contains your files; make sure the box next to the directory name in the
left half of the pop-up window is checked, which will cause the files in
that directory to be displayed in the right half; check only the files you
want (click Deselect to uncheck them all first)
fill in the Into Folder box with your project name
click Finish
your navigator should show your new file (you may have to point the
arrow next to your project name downward)
Keep in mind that the behavior of the Debug perspective
will vary from one language to another. But here are the features in
common:
you must be in the Debug perspective to debug
to run within Debug, you can select Run | Debug
but a shortcut is to click the Debug icon
near the upper left of your screen
to set a breakpoint, double-click in the border to the left of
the source line
to make a breakpoint conditional, right-click on the breakpoint
symbol to the left of the given line, and select Breakpoint
Properties... | Common
to remove or temporarily disable a breakpoint, right-click on
the breakpoint symbol to the left of the given line; note that
Toggle means to remove the breakpoint, while
Disable/Enable means what it says
to have a breakpoint apply only to a particular thread, right-click
on the breakpoint symbol to the left of the given line, and select
Breakpoint Properties... | Filter ; uncheck the boxes
of the threads in which you do not want the breakpoint to apply
breakpoints will be retained from session to session
the current source code line (i.e. next line to be executed) will
be highlighted in green; upon startup, that will be the first line in
main() (or similar location, depending on the
language); in other words, an automatic breakpoint is set there
to resume execution (or start execution, if at the first line of
main()), click on the resume icon at the left end
of the debugger toolbar
the usual step-in/step-over/step-return operations are available
the Variables view is very useful:
this view shows the values of your variables
local variables are displayed according to the current scope
global variables are by default not displayed, but you can
change that by right-clicking this view and selecting
Add Global Variables
a link for a pointer variable may be followed, by pointing
the triangle next to the variable downward; this may be done
repeatedly, to display a linked list etc;
if a pointer points to a dynamically created array, the entire
array (or a subarray) may be displayed by right-clicking the variable
and selecting Display As Array
you can change the value of a variable by right-clicking its
name and choosing Change Value
the Breakpoints view helps you manage all your
breakpoints
to restart your program from the beginning, click the
Restart icon in the Debug toolbar
to kill your program but remain in the debugger, first select the
currently-running thread, and then click on the Pause
icon in the Debug toolbar; do NOT click on the red
Terminate icon unless you want to start a new debugging
session
while in the Debug perspective, you still have the
edit window there (it's where you set the breakpoints etc. too); any
changes you make there are the same as if you were in your development
perspective; however, you cannot compile directly (under the simple
rules given here), and must return to your development perspective
Make good use of these! While you are editing, the Outline
view will show you where your major code objects are, i.e. functions,
classes, etc. Clicking on one will make the editor jump to that spot in
the code.
The same is true for debugging. If you need to set a breakpoint at some
function, for instance, click on its name in the outline, which will
bring you right there, so you can set the breakpoint.
a common error message is stopped due to shared
libraries; in this case, you may have multiple debug sessions
going; you can kill them all via Terminate All
Launched; or you may need to terminate a program, by hitting
the red square
We'll illustrate the process for the C/C++ plugin,
CDT. If you don't already have CDT (you can check by
selecting Window | Show View, possibly clicking on
Other), do the following:
You can install a plugin "by hand," or by using
Eclipse's built-in plugin download/installation
feature. Let's look at the latter first.
A plugin comes as .zip files, which packages the
various .jar and other files of the plugin.
Unzip the plugin, and copy the contents of the
features and plugins directories get
copied to Eclipse's corresponding directories. For
example, say your Eclipse plugins directory is
/usr/local/eclipse/plugins and you have unzipped your
plugin package in /tmp. Then within
/tmp, run
$ cp -r features plugins /usr/local/eclipse
(This is for Linux; adjust accordingly for Windows.)
After a manual installation, restart Eclipse with the
-clean command-line option.
You may wish to put some plugins in a different directory from the one
set up when Eclipse was installed. For instance, you
may be using a multiuser machine and not have write access to the
standard plugins directory. In that case, you can form your own
supplementary plugins directory. See
Colin's blog for directions on how to do this.