Environment variables

QNX SDP8.0Building Embedded SystemsConfigurationDeveloper

Host-side environment variables can be accessed in a buildfile. All occurrences of ${NAME} are replaced by the value of the environment variable with the given name. You can set additional variables in the buildfile to define the environment of any processes started on the target at boot time.

For environment variables set in the buildfile:
  • A buildfile line of the form varname=value progname arguments... creates a local variable and adds varname=value only to the environment of that one process.
  • A buildfile line of the form varname=value creates a global variable whose setting is added to the environment of every process started below in the buildfile. You must carefully consider the effects of such settings made early in the buildfile, particularly in the bootstrap file (i.e., the first section) as explained below.
  • Global variables can be accessed just like regular host environment variables by using ${varname}.

Note that only environment variables defined in the buildfile are visible on the target.

Setting environment variables in the bootstrap file

Setting an environment variable in the bootstrap file sets this variable not only for subsequent bootstrap executables but also for any executables in any script files. For variables meant to hold a list of possible search paths, this can be an efficient strategy. But if you want to set a variable for one specific executable, then you must define it as a local variable. For example, suppose we want to define PATH and LD_LIBRARY_PATH for all processes, but also we want to define another variable, CONFIG_PATH, for the process manager only. We would then set CONFIG_PATH on the same line as the procnto-smp-instr command, as follows:
[image=0x80200000]
[virtual=aarch64le,elf] .boot = {
    startup-honeycomb_lx2 -W 
    PATH=/proc/boot:/sbin:/bin:/usr/bin:/usr/sbin:/usr/libexec 
    LD_LIBRARY_PATH=/proc/boot:/lib:/usr/lib:/lib/dll:/lib/dll/pci 
    CONFIG_PATH=/etc/cfg procnto-smp-instr -v
}

Setting environment variables in a script file

If you want to define certain environment variable settings for one or more user processes, then you can do so in the script file that follows the bootstrap file. As an example, consider the earlier buildfile excerpt shown in Buildfile structure and contents in which the SYSNAME, TERM, and ENV variables are defined at the beginning of the script file and, thus, apply for all user processes. Suppose we then define the PATH variable for a specific process later on:
[image=0x80200000]
[virtual=aarch64le,elf] .boot = {
    ...
}

[+script] .script = {
  SYSNAME=nto
  TERM=qansi
  ENV=/etc/profile
  procmgr_symlink ../../proc/boot/ldqnx-64.so.2 /usr/lib/ldqnx-64.so.2
  ...
  devc-ser8250-abc123 -F -e -c14745600 -b115200 0xc8000000 ^2,15 &
  ...
  PATH=/proc/boot:/bin esh &
}
You can check the variable definitions by running dumpifs on the OS image file:
dumpifs -vv myimage.ifs
Two -v options are needed to print the environment variable settings that are passed to each process started in the buildfile.
Running the above command on the image file with the script file shown above would then output:
SYSNAME=nto TERM=qansi ENV=/etc/profile devc-ser8250-abc123 -F -e \
-c14745600 -b115200 0xc8000000 ^2,15 &

SYSNAME=nto TERM=qansi ENV=/etc/profile PATH=/proc/boot:/bin esh &

Defining search paths of utilities and libraries

The procnto-smp-instr process manager uses the value of its PATH variable to set the _CS_PATH configuration string. Similarily, it sets the _CS_LIBPATH configuration string to the value of its LD_LIBRARY_PATH variable. For more information about setting these environment variables in the buildfile, see Setting PATH and LD_LIBRARY_PATH in the QNX OS User's Guide.

Host-side environment variables used for generating the target image

The host environment variable MKIFS_PATH is used to control where mkifs looks for the files it places in the image (see Including files in the image in this chapter). You can set it when running mkifs to define primary lookup paths. Additional root directories specified with the mkifs -r options append path lists to this variable; another path list rooted in ${QNX_TARGET} is appended at the very end.

The PROCESSOR, PROCESSOR_BASE, and CPU_BASE environment variables are set by the virtual attribute of the bootstrap file. They are used in constructing the MKIFS_PATH path lists.

Note:
The variables described here (especially MKIFS_PATH) are meaningful only on the host. They should not be set explicitly in the buildfile, because they should not appear on the target.
Page updated: