Linker Command File Preprocessing (--disable_pp, --define and --undefine Options)

The linker preprocesses linker command files using a standard C preprocessor. Therefore, the command files can contain well-known preprocessing directives such as #define, #include, and #if / #endif.

Three linker options control the preprocessor:

--disable_pp Disables preprocessing for command files
--define=name[=val] Predefines name as a preprocessor macro
--undefine=name Removes the macro name

The compiler has --define and --undefine options with the same meanings. However, the linker options are distinct; only --define and --undefine options specified after --run_linker are passed to the linker. For example:

cl2000 --define=FOO=1 main.c --run_linker --define=BAR=2 lnk.cmd

The linker sees only the --define for BAR; the compiler only sees the --define for FOO.

When one command file #includes another, preprocessing context is carried from parent to child in the usual way (that is, macros defined in the parent are visible in the child). However, when a command file is invoked other than through #include, either on the command line or by the typical way of being named in another command file, preprocessing context is not carried into the nested file. The exception to this is --define and --undefine options, which apply globally from the point they are encountered. For example:

--define GLOBAL #define LOCAL #include "incfile.cmd" /* sees GLOBAL and LOCAL */ nestfile.cmd /* only sees GLOBAL */

Two cautions apply to the use of --define and --undefine in command files. First, they have global effect as mentioned above. Second, since they are not actually preprocessing directives themselves, they are subject to macro substitution, probably with unintended consequences. This effect can be defeated by quoting the symbol name. For example:

--define MYSYM=123 --undefine MYSYM /* expands to --undefine 123 (!) */ --undefine "MYSYM" /* ahh, that's better */

The linker uses the same search paths to find #include files as it does to find libraries. That is, #include files are searched in the following places:

  1. If the #include file name is in quotes (rather than <brackets>), in the directory of the current file
  2. In the list of directories specified with --Iibrary options or environment variables (see Section 8.4.17)

There are two exceptions: relative pathnames (such as "../name") always search the current directory; and absolute pathnames (such as "/usr/tools/name") bypass search paths entirely.

The linker provides the built-in macro definitions listed in Table 8-10. The availability of these macros within the linker is determined by the command-line options used, not the build attributes of the files being linked. If these macros are not set as expected, confirm that your project's command line uses the correct compiler option settings.

Table 8-10 Predefined C28x Macro Names

Macro Name Description
__DATE__ Expands to the compilation date in the form mmm dd yyyy
__FILE__ Expands to the current source filename
__TI_COMPILER_VERSION__ Defined to a 7-9 digit integer, depending on if X has 1, 2, or 3 digits. The number does not contain a decimal. For example, version 3.2.1 is represented as 3002001. The leading zeros are dropped to prevent the number being interpreted as an octal.
__TI_EABI__ Defined to 1 if EABI is enabled; otherwise, it is undefined.
__TIME__ Expands to the compilation time in the form "hh:mm:ss"
__TMS320C2000__ Defined for all C2000 processors
__TMS320C28XX__ Defined if target is C28x
__TMS320C28XX_CLA__ Defined to 1 if and --cla_support is used; otherwise it is undefined.
__TMS320C28XX_CLA0__ Defined to 1 if --cla_support=cla0 is used; otherwise it is undefined.
__TMS320C28XX_CLA1__ Defined to 1 if --cla_support=cla1 is used; otherwise it is undefined.
__TMS320C28XX_CLA2__ Defined to 1 if --cla_support=cla2 is used; otherwise it is undefined.
__TMS320C28XX_FPU32__ Defined to 1 if --float_support=fpu32 is used; otherwise it is undefined.
__TMS320C28XX_FPU64__ Defined to 1 if --float_support=fpu64 is used; otherwise it is undefined.
__TMS320C28XX_IDIV__ Defined to 1 if --idiv_support=idiv0 is used; otherwise it is undefined.
__TMS320C28XX_TMU__ Defined to 1 if --tmu_support is used with any setting; otherwise it is undefined.
__TMS320C28XX_TMU0__ Defined to 1 if --tmu_support is used with any setting; otherwise it is undefined.
__TMS320C28XX_TMU1__ Defined to 1 if --tmu_support=tmu1 is used; otherwise it is undefined.
__TMS320C28XX_VCU0__ Defined to 1 if --vcu_support=vcu0 is used; otherwise it is undefined.
__TMS320C28XX_VCU2__ Defined to 1 if --vcu_support=vcu2 is used; otherwise it is undefined.
__TMS320C28XX_VCRC__ Defined to 1 if --vcu_support=vcrc is used; otherwise it is undefined.