This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS5.2.0 a predefine in a .c file does not propagate to other files

Other Parts Discussed in Thread: TMS320C28346

I have a .c file in which I define, let's say :

#define EXPORT_H

then I include a .h file :

#include "test.h"

If I try to use this predefine for something in the included .h file, like:

#if defined(EXPORT_H)

I never get the expression to be true. The only way I can solve this is including a predefine in project option in the respective .c file ...

Am I doing something wrong ?

  • Please show a complete, compilable test case which demonstrates the problem.

    Are you sure you include test.h before attempting to use EXPORT_H?

    Are you sure you haven't got conditional compilation (#if) in test.h which is disabling the definition of EXPORT_H?

    Are you sure you've spelled it correctly in all places?

  • It ought to work.  One possibility is that he #includes "test.h" twice (directly or via other headers), with the #define EXPORT_H in between, and inside test.h there may be what in the trace we call an "idempotency lock", along the following lines:

    #ifndef TEST_H_INCLUDED; #define TEST_H_INCLUDED; ... contents here ... #endif

    I think the default template for creating *.h files within CCS may automatically add that stuff.  Then the contents of the header will be inactive during its second #inclusion.

  • I think something in the project setting may be wrong, because creating a new hello project for the TMS320C28346 and having:

    my hello.c file:

    #include <stdio.h>

    /* Module header */
    #define EXPORT_HELLO_H
    #include "hello.h"
    #undef EXPORT_HELLO_H


    /*
    * hello.c
    */
    void main(void) {
    printf("Hello World!\n");
    }

    and my hello.h header file:

    #ifndef _HELLO_H
    #define _HELLO_H


    #ifdef __cplusplus
    extern "C" {
    #endif

    #if defined(EXPORT_HELLO_H)
    #define EXTERN
    #define INIT(x) = x
    #else
    #define EXTERN extern
    #define INIT(x)
    #endif

    #if defined(EXPORT_HELLO_H)
    #error OK is defined
    #endif


    /* Other code */
    #ifdef __cplusplus
    }
    #endif
    #undef EXTERN
    #undef INIT
    #endif /* HELLO_H */

    Compiling gets correctly this output:

    C:\TI\ccsv5\utils\bin\gmake -k all
    'Building file: ../hello.c'
    'Invoking: C2000 Compiler'
    "C:/TI/ccsv5/tools/compiler/c2000_6.1.0/bin/cl2000" -v28 -ml -mt --float_support=fpu32 -g --include_path="C:/TI/ccsv5/tools/compiler/c2000_6.1.0/include" --diag_warning=225 --display_error_number --diag_wrap=off --preproc_with_compile --preproc_dependency="hello.pp" "../hello.c"
    "..\hello.h", line 18: fatal error #35: #error OK is defined
    1 fatal error detected in the compilation of "../hello.c".

    Compilation terminated.
    >> Compilation failure
    gmake: *** [hello.obj] Error 1
    gmake: Target `all' not remade because of errors.

    **** Build Finished ****


    But if I do the same thing in another project, I can't get the "#error OK is defined" during compilation....

    This time the project is made up of more source and header files. This project is originally a CCS 3 project, imported in CCS4 and finally in CCS5...

    Maybe some project settings ? Summary of the flags set in project properties are:

    -v28 -ml -mt --float_support=fpu32 -O0 --symdebug:coff --include_path="C:/TI/ccsv5/tools/compiler/c2000/include" --include_path="C:/TI/xdais_7_21_01_07/packages/ti/xdais" --include_path="../include" --include_path="../include/DSP2834x" --define="_DEBUG" --define="LARGE_MODEL"  --diag_warning=225 --display_error_number --issue_remarks

    The source and header files use the same #include structure, the only noticeable difference is that in the first project the header and source file are in the same directory, while in the second project (non working one) the source and header files are in different directories...

    I am sure they are correctly spelled and no wrong conditional compilation is place. I will try to reproduce this behavior in a "template project" ..... 

  • Make sure you are including hello.h; add an #error to the top of hello.h, before the #ifndef

  • Make sure the "include path" used by the compiler contains the directory where the header is kept.

    Also be sure you have not enabled the use of "precompiled headers".