Getting started developing with Eclipse
This page shows the basic steps to setup a project and start debugging in the Eclipse IDE in Linux. There are also many additional tutorials online. For more information, google: eclipse C tutorial
Estimated time to complete: 20mins.
Prepare your source
Compile your code with debugging symbols as described here.
Install gdb and Eclipse with the C/C++ development tools (cdt)
| Fedora |
# yum install gdb eclipse-cdt |
| Ubuntu |
# apt-get install gdb eclipse-cdt |
If Eclipse is not in your distribution repository it can be downloaded from here: Eclipse IDE for C/C++ Developers (68 MB)
Eclipse Development
The following steps assume that you have an existing autoconf-based project such as you might create using Linux Project Generator. You can also use an existing non-autoconf-based project or use the Eclipse wizards to create a new project (not covered exactly here, but the steps are very similar).
Start Eclipse. Open the C/C++ Perspective
$ eclipseAfter Eclipse starts you can change your "Perspective" which is the layout of "Views" in the application. Open the C/C++ Project perspective:
From top menu, select: Window + Open Perspective + C/C++ Project
Step 2: Create an empty project
We have an existing C project already outside of Eclipse. We are going to create a new empty project in Eclipse and populate it with our source.
From top menu, select: File + New + Project...

In the General category, select "Project". (Note: If you want to have Eclipse create a new project (with source), you can pick another option here.)

Enter a project name. Spaces are discouraged as they can cause problems later when building.
Select where the project should be located. Note the trade-offs. If you check "Use default location", all the project source will be copied to this directory. The downside is that if you modify this copied source you'll have to figure out how to get it checked into your source repository. If you don't use the default location and instead specify your project's existing source directory then Eclipse will copy project configuration files and directories into your source tree. For example:
.../ <project source dir> /
.cdtproject
.project
.externalToolBuilders
.settings
For simplicity of this article, we used the default Eclipse location.

Step 3: Import your source into your project
Right-click on the project. Select "Import..."


Enter the path to your project root directory. The following is using the sample apps source. Place a check next to any files or directories you wish to import into your project.

When finished your project is populated and you are ready to build.

Step 3: Build your project in Eclipse
Now that our project is populated with our code, we want to tell Eclipse that this is a C/C++ project. Right-click the project and select New + "Convert to a C/C++ Make Project".

Now we will configure 2 project builders: autogen and make.
From the top menu, select: Project + Properties.

autogen Builder
Click "New..." to create a new Builder. Select "Program". Enter "autogen" as the name. For Location, click "Browse Workspace" and select the autogen.sh file. For Working Directory, click "Browse Workspace" and select your project.

Go to the Build Options tab and click the "Specify working set of relevant resources" checkbox, then the "Specify Resources" button. In the dialog select any files that would require re-running autogen.sh. For example: autogen.sh, configure.ac, Makefile.am, src/Makefile.am. This will force autogen.sh to be re-run anytime any of these files changes. (It is very convenient).

Click Finish to save.
Last, move autogen to the top of the "Builders" list.

make Builder
Since we converted our project to a C/C++ Make project, Eclipse added the necessary "make" builder. Select "C/C++ Make Project" on the left. Set the Build Location / Build directory to the project root directory (or wherever you want "make" to be run).
Build!
From the top menu, select: Project + Build Project.
First autogen.sh is run. Then make is run. You can see the output in the "Console" view.

Step 4: Debug your project
Our project is built and ready to debug. First we create a "Run configuration" which will contain the run/debug configuration information.
From the top menu, select: Run + Debug...

Right-click "C/C++ Local Application" on the left, and click "New..."

The "ClutterHelloWorld" project is automatically created as the default run configuration. Select the "Search Project" button to pick our executable to run. Select the projects generated binary (created when the project was built). For our example, "helloworld" is the binary.

Click "Debug" to save our configuration and start debugging the application. Eclipse asks if we want to switch to the Debug Perspective. We do.

Important Debug Key Mappings
You can use the "Run" menu to step through the code. However, the following keys are more convenient:
| Key | Function |
| F11 | Start debugging |
| F6 | Step Over |
| F5 | Step Into |
| F8 | Resume/Continue |
Step 5: (Optional) Customize the perspective
A "Perspective" is a defined layout of views on the screen. Eclipse has a few defaults such as "C/C++ Projects" and "Debug". The views are easy to reorganize simply by dragging them around the screen. You can also add new views by selecting Window+ShowView+<View name>. Below is my preferred layout.

- Printer-friendly version
- Login or register to post comments

Comments (3 total)
how to get on moblin book itself?
I'm looking for instruction, either on getting eclipse, anjuta, or at the very least geany as an ide I can use on my moblin netbook.
can I access the sample code?
can I access the sample code?
Access Denied You are not authorized to access this page.
Do not acces to :
sample apps source
Access Denied
You are not authorized to access this page.
How can access the sample code ?