Eclipse IDE with OpenAccess

by John McGehee on November 3, 2008

Eclipse works great for me as an C++ integrated development environment (IDE) for OpenAccess-based applications. It supports all the same platforms as OpenAccess, and it’s free software.

This article addresses C++ application development using Eclipse CDT.  I wrote another article on using Eclipse PyDev to develop OpenAccess Python applications.

Here’s how to get started. Your comments and corrections are always appreciated.

Launch Eclipse

Eclipse can be launched Applications > Programming > Eclipse menu command.  However, if you do this Eclipse will not pick up your shell environment. If you want to debug programs that depend on variables defined in your shell environment, launch Eclipse from the shell command line,

eclipse &

and the Eclipse session will inherit your shell environment.  You can define more environment variables for a debugging session using the Debug Configurations dialog.

Create an Eclipse Workspace

  • Download and install Eclipse IDE for C/C++ Developers. Eclipse is included with most Linux distributions, but an update to the latest version is worthwhile. Only C/C++ Development Tooling (CDT) version 4.0 and above are professional quality.
  • Choose a workspace directory that will contain OpenAccess and related applications, for example, /home/voom/src. You probably already have such a directory–just use it as is.
  • Start Eclipse. In Gnome, it can be executed by selecting Applications > Programming > Eclipse from the menu.
  • Specify your workspace path, like /home/voom/src
  • The Eclipse Resource screen will appear. Select Workbench – Go to the workbench. The Eclipse workbench appears. This is where you will be spending most of your time in Eclipse.

Create a Project for Each of Your Applications

  • If your application already exists, check out the source hierarchy to a suitable location within your workspace, such as /home/voom/src/mower/oa2mw
  • Right click in the Project Explorer window. In the context menu, select New > C++ Project to create a new project for your application. Alternatively, select the menu command File > New > C++ Project.
    • Specify a project name, such as oa2mw
    • The default project location is the directory with the same name as the project, immediately under the workspace directory. If this is not the case, uncheck Use default location, and specify the path within the workbench, such as /home/voom/src/mower/oa2mw.
    • Select from the Project Types:
      • If your application already has source and build files, select Executable > Empty Project so that Eclipse will not add any files
      • If you are starting a new application, choose the type of Project types that matches your style
    • Advance to Select Configurations by clicking Next. Two configurations, Debug and Release are available by default. They should be sufficient for now. You can easily add more later.
    • If you will be using your own Makefile, rather than the Eclipse internal builder,
      • Click Advanced settings. Select C/C++ Build.
        • Select Configuration Debug
          • Uncheck Use default build command
          • Specify the appropriate command to build your application for debug, such as make OPTMODE=dbg
          • If the default Build directory is incorrect, uncheck Generate Makefiles automatically
          • In Build directory, specify the working directory in which your Makefile should be run, for example, ${workspace_loc:/mower/way/Debug}
          • Click Apply
        • Select configuration Release
          • For most applications, the default Build command (make) is in fact the correct release build command. If not, uncheck Use default build command, and specify the command to build your application optimized, such as make OPTMODE=opt.
          • If the default Build directory is incorrect, uncheck Generate Makefiles automatically
          • In Build directory, specify the working directory in which your Makefile should be run, for example, ${workspace_loc:/mower/way/Release}
          • Click Apply
        • Click OK
    • Click Finish to create the project. If the Select Configurations dialog refuses to close, make sure the Location you specified is a full path to an existing location within the workspace.
  • A dialog may ask, This kind of project is associated with the C/C++ perspective. Do you want to open this perspective now? A perspective is an arrangement of windows within the Eclipse workbench. Click Yes, and the C/C++ perspective appears. This perspective is suitable for writing code. Later, you will encounter the Debug perspective that displays different windows suitable for debugging.
  • Your project now appears in the the Project Explorer window. Expand folders by single clicking, and open files by double clicking.
  • To build OpenAccess for the currently active configuration, use the Project > Build Project command

Create a Project for OpenAccess

If you want to use Eclipse to edit and recompile OpenAccess, you must download OpenAccess to a location within your Eclipse workspace. For this, use the following procedure.

OpenAccess comes with pre-compiled libraries that work fine. If you do not need to recompile OpenAccess yourself, you can put OpenAccess in a location outside your workspace, and add OpenAccess as a linked folder.

Set Up the Project

  • Download OpenAccess to a suitable location within your workspace, such as /home/voom/src/oa/22.04p028
  • Create a new project for OpenAccess. Right click in the Project Explorer window. In the context menu, select New > C++ Project. Alternatively, select the menu command File > New > C++ Project.
    • Specify a project name, such as OA
    • Uncheck Use default location, and specify the Location of the oa/ directory within the OpenAccess software, such as /home/voom/src/oa/22.04_p028/oa
    • Since OpenAccess is already complete with all source and build files, select Executable > Empty Project so that Eclipse will not add any files. The other Project types choices are more useful when you start a new project.
    • Click Next to advance to the Select Configurations. Two configurations, Debug and Release are available by default.
    • Click Finish to dismiss the Select Configurations dialog. If the dialog refuses to close, make sure the Location you specified is a full path to a location within the workspace.
  • A dialog will ask, This kind of project is associated with the C/C++ perspective. Do you want to open this perspective now? A perspective is an arrangement of windows within the Eclipse workbench. Click Yes, and the C/C++ perspective appears. This perspective is suitable for writing code. Later, you will encounter the Debug perspective that displays different windows suitable for debugging.
  • Project OA now appears in the the Project Explorer window. Expand folders by single clicking, and open files by double clicking.

Set Up Building

  • Create an oa_install target for the Debug configuration
    • Right click on the OA project in the Project Explorer folder. Set the active configuration to Debug using Build Configurations > Set Active > Debug.
    • Right click on the OA project in the Project Explorer folder. Select Make targets > Create in the context menu. The Create a new Make target dialog appears.
      • Specify oa_install for both Target Name and Make Target
      • Specify make OPTMODE=dbg for Build command
      • Click Create
  • Create an oa_install target for the Release configuration
    • Right click on the OA project. Set the active configuration using Build Configurations > Set Active > Release.
    • Right click on the OA project. Select Make targets > Create in the context menu. The Create a new Make target dialog appears.
      • Specify oa_install for both Target Name and Make Target
      • Specify make OPTMODE=opt for Build command
      • Click Create
  • To build OpenAccess for a configuration,
    • Right click on the OA project. Set the active configuration using the Build Configurations > Set Active command.
    • Right click on the OA project. Select Make targets > Build
    • In the dialog, select oa_install
    • Click Build to recompile OpenAccess

Add OpenAccess to Your Application Project as a Linked Folder

If you want to put OpenAccess in a location outside your workspace and merely refer to it, add OpenAccess to your application project as a linked folder using the following procedure. This works best for larger organizations where multiple client application developers use the same stable OpenAccess release.

However, you will not be able to edit and recompile OpenAccess. If you want to do this, add OpenAccess as a distinct Eclipse project.

  • In the Project Explorer, right click to select the project to which you want to add OpenAccess
  • In the context menu, select New > Folder. Alternatively, select the menu command File > New > Folder. The New Folder dialog appears.
  • Specify a folder name, like OA
  • Click the Advanced button. The dialog expands to show more options.
  • Click Link to alternate location (Linked Folder)
  • Specify the path to the oa/ directory within the OpenAccess software, such as /usr/local/eda/oa/22.04_p028/oa
  • Click Finish

Set Up Project Dependencies

Here I assume that you will be using your own Makefile, not the Eclipse internal builder.

  • Establish the relationship between your application and OpenAccess:
    • If you created a project for OpenAccess, Right click on your project in the Project Explorer folder. Select Properties. In the Project References section of the Properties dialog, check OA and any other projects on which this project depends.
    • If OpenAccess is not a project within your Eclipse workspace, follow the instructions to create a linked folder within your application’s project.
    • Repeat for the other projects on which you project depends
    • If you edit project dependencies, Re-index so that Eclipse can navigate to the newly added source code. Right click on your project in the Project Explorer folder. Choose one of the Index sub-menu commands to partially or completely re-build the source code index.

Debug Your Application in Eclipse

Debugging is what makes an IDE really cool.

In order to debug, you must tell Eclipse how to run your application. You do this using a Launch Configuration. The word “launch configuration” is not prominent in Eclipse.  Instead you see Run Configuration and Debug Configuration.  I fail to see the difference between them—to me they all appear to be exactly the same. Since this article is about debugging, I’ll call them Debug Configurations.

Create a Debug Configuration

In the Project Explorer, select the project containing the application you want to debug.

Select the Run > Debug Configurations menu command:

  • In the left pane, select the type of program you want to debug, presumably a C++ Application.  Create a new configuration by clicking the New Launch Configuration icon in the upper left of the dialog.
  • Give the debug configuration a useful Name.  The default is the currently active project name.
  • In the Main tab,
    • Enter the path to the C/C++ Application you want to debug
    • Enter the Project name, which defaults to the project name that you already selected
  • In the Arguments tab,
    • Enter the Program arguments to apply when running the C/C++ Application you earlier specified in the Main tab
    • Deselect Use Default in the Working directory box if you want to specify the working directory in which the application should run
    • Specify the Working Directory in which the C/C++ Application should run. It is convenient to use Eclipse variables for this. For example, assuming that the current Eclipse workspace is at ~/workspace,
          ${workspace_loc:oaeFigSet/test}

      evaluates to ~/workspace/oaeFigSet/test.

  • In the Environment tab,
    • Enter the Environment variables to set before running the C/C++ Application
    • Select New and enter a variable name and value for each variable you want to set, like LD_LIBRARY_PATH
    • The default is to Append environment to native environment, but if you want to override the settings in your environment, the default is not appropriate. Consider the other option, Replace native environment with specified environment.
  • In the Debugger tab,
    • You may wish to deselect Stop on startup at: Main
  • Click Apply

Running the Debugger

Now that you have created a Debug Configuration, try running the debugger. If you still have the Debug Configuration dialog open, you can click Debug. On subsequent tries, again select the Run > Debug Configurations menu command.

There are many tutorials on the internet that show you how to operate the debugger. I will not go into it here.

Leave a Comment

Previous post:

Next post: