What determines the value of an environment variable

Environment variables define the environment used by the compiler and executables launched from Project Manager. Where and when the environment variable is important.

Order of precedence

An environment variable can be set in multiple places, inside and outside of Genero Studio. Environment variables have an order of priority (high to low):

  1. The environment defined on the node itself (Genero variables and User variables). This has the highest priority.
  2. The environment of the node's parents (ancestors).
  3. The environment of the node's dependencies.
  4. Environment variables defined in the current language.
  5. Environment variables defined in Environment sets.
  6. System environment variables. This has the lowest priority.

The order of priority allows you to override both system environment variables (6, above) or environment variables defined in a Genero Studio configuration (5, above) by setting them in Project Manager (1 through 4, above).

Order within an Environment Set

Within an Environment Set, Arrow keys can be used to change the order of the variables defined. This affects the way the variables are interpreted when the program is executed. For example:

Table 1. Variable interpretation examples
Project level Variables definition and order Result when application is executed
Project V1="hello"  
Application V2="$(V1) world"

V1="goodbye"

V1="goodbye"

V2="hello world"

Application

V1="goodbye"

V2="$(V1) world"

V1="goodbye"

V2="goodbye world"

Note: If a foreign language Language support (text encoding) is selected in Genero Studio preferences, the LANG variable must be set appropriately to correspond to the selected encoding. Set the variable for a specific environment set in Genero Studio configurations (Tools>>Configurations).

Example: Priority and Environment Variables

In this example, the program node in the project has a library node as a dependency. The environments have been defined as shown:

Table 2. Environment Set for levels used in the example
Level Environment Set
System environment
PATH=/bin;/usr/bin 
VAR1=hello 
VAR2=bonjour 
VAR3=guten tag
My Library Environment
PATH=$(PATH);$(ProjectDir)/scripts 
VAR1=goodbye
My Program Environment
PATH=$(PATH);$(ProjectDir)/scripts 
VAR1=$(VAR1) world 
VAR2=$(VAR2) $(VAR1)

If the project directory $(ProjectDir) is set to "/home/joe/project", the environment for the program will be:

PATH=/bin;/usr/bin/;/home/joe/project/scripts 
VAR1=goodbye world 
VAR2=bonjour goodbye world 
VAR3=guten tag