Eclipse Build Variables


This post is not about variables in my application code (which I debug). It is about using Variables in Eclipse for building projects. Eclipse variables allow me to make my projects ‘position independent’ whenever I cannot use a path relative to my projects or workspace.

Eclipse Variables

Which variables are used where in Eclipse might be sometimes not very clear. Depending in which context variables are used, not everything might be available. This link for example gives a list of variables which can be used to invoke an external tool.

Build Variables

Eclipse comes with many built-in variables, especially for the build system. If I want to see what variables are already defined, I can show them in the project properties, under C/C++ Build > Build Variables with enabled option ‘Show system variables':

System Build Variables

System Build Variables

With the ‘Add…’ button I can define and add my own variables, available for that project:

Define a new build variable

Define a new build variable

If above operation is done on a project, then the setting is for the project only. If I want to add a variable for the workspace, I can do this using the menu Window > Preferences:

Workspace Build Variables

Workspace Build Variables

Global System Variables

Eclipse automatically includes the system (e.g. Windows) environment variables. Many dialogs have the ‘Variables…’ button where I can use my variables, including the variables defined on system level:

System Variables

System Variables

System variables: one way or the other

So if I want to have a variable for every workspace, one way is to define it at the system level. However, this is not a good way as this clutter the variables for every application.

Batch File

A solution to this to create my custom batch file where I define my variables, and at the end of this batch file I launch Eclipse. That way the extra variables are only for this Eclipse session.

cwide-env File

Another very nice way CodeWarrior Eclipse offers is using the cwide-env file located in the eclipse sub-folder of the installation:

cwide-env File

cwide-env File

I can define variables here, or extend existing ones:

  • -add: add string to the variable at the end
  • -prepend: add string to the variable at the beginning

That way I can easily manipulate existing system variables or create new ones which then are used by Eclipse.

Summary

Variables in Eclipse help me to define paths to source files and folders outside of a project or workspace. With variables I avoid using absolute paths which would make porting projects from one machine to another difficult. I can define variables for projects, for the workspace or use system variables. With CodeWarrior I have a cwide-env file which is used to extend the system variables.

Happy Variabling :-)

About these ads

One thought on “Eclipse Build Variables

  1. Pingback: Link to Files and Folders in Eclipse | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s