FAQ-110802-1

From RTSC-Pedia

Jump to: navigation, search
revision tip
—— LANDSCAPE orientation
[printable version]  [offline version]offline version generated on 18-Nov-2017 00:11 UTC

FAQ-110802-1

I'm getting compiler errors from xdc/cfg/global.h

The header xdc/cfg/global.h is designed to enable application C files to portably include configuration-specific definitions and declarations of constants and variables; see FAQ-081229-2.

This header works by simply #include'ing the configuration-specific header generated as part of the configuration process. But, in order for xdc/cfg/global.h to be independent of the configuration, the configuration-specific file it includes is specified by a symbol, xdc_cfg__header__, which must be defined in the compiler's command line; see Portable Inclusion of Configuration Constants.

This is where the problem comes in. According to the rules of the C pre-processor, the value of xdc_cfg__header__ is also subject to macro substitution. As a result, if any token in the value of this symbol matches a #define appearing before the #include of xdc/cfg/global.h, it will replace the token and, almost certainly, result in an invalid header file name.

In the example below, suppose that xdc_cfg__header__ is defined to be "stdin/package/cfg/main_p430.h". Since stdio.h typically defines stdin to be a macro that expands to be a reference to an element of global array, say &_ftable[0], the xdc/cfg/global.h header will attempt to include a header whose name includes the string "&_ftable[0]"!

main.c
 
 
 
 
 
 
 
#include <stdio.h>
#include <xdc/cfg/global.h> /* WARNING: definitions above may interfere with this header */
 
int main(void) {
    printf("%s\n", myString);
    return (0);
}

possible error output
 
 
 
".../xdc/cfg/global.h", line 39: fatal error: could not open source file "&_ftable[0]/package/cfg/main_p430.h"
1 fatal error detected in the compilation of "main.c".
Compilation terminated.

The solution is to simply move the #include of the xdc/cfg/global.h ahead of all other headers.

main.c (better)
 
 
 
 
 
 
 
#include <xdc/cfg/global.h> /* it's safer to include this first */
#include <stdio.h>
 
int main(void) {
    printf("%s\n", myString);
    return (0);
}

[printable version]  [offline version]offline version generated on 18-Nov-2017 00:11 UTC
Copyright © 2008 The Eclipse Foundation. All Rights Reserved
Personal tools
package reference