DevOps Zone is brought to you in partnership with:

Erich is Professor at Lucerne University of Applied Sciences and Arts and Distinguished Member of Technical Staff at Freescale Semiconductor. Erich has a MsCS degree and 18+ years of experience in the embedded software and tools world. He created many embedded cross C/C++ compilers and debuggers. Additionally he is researching in the domain of programming languages, real time and mechatronic systems. Erich is a DZone MVB and is not an employee of DZone and has posted 98 posts at DZone. You can read more from them at their website. View Full User Profile

Eclipse Build Variables

  • submit to reddit

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.


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 :-)

Published at DZone with permission of Erich Styger, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)