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.

Using preprocessor directives in linker command file

Hi, I want to have several linker command files in my project, which should be conditionally included based on predefined macros. However, when using one (e.g. #ifdef DSP28_2809) in the beginning of a file, it seems to not include the file regardless of DSP28_2809 being set.

I have set the macro in C2000 Compiler -> Advanced Options -> Predefined Symbols, and the linker seems to recognize this:

"C:/Program Files/Texas Instruments/C2000 Code Generation Tools 6.1.0/bin/cl2000" -v28 -ml -mt -g --gcc --define=DSP28_2809=1 --define=DSP28_RAM=1 --define=CPU_FREQ=100000000 --diag_warning=225 --display_error_number -z --stack_size=0x300 -m"gpu.map" --warn_sections -i"C:/Program Files/Texas Instruments/C2000 Code Generation Tools 6.1.0/lib" -i"D:/Projects/gpu/lib/pec-lib/debug/crosshairs" -i"C:/Program Files/Texas Instruments/C2000 Code Generation Tools 6.1.0/include" --reread_libs --rom_model -o "gpu.out"  "./lib/pec-lib/app/events/events.obj" "./lib/pec-lib/drivers/ti_c28x/adc/adc_012.obj" "./lib/pec-lib/drivers/ti_c28x/ecan/ecan_0.obj" "./lib/pec-lib/drivers/ti_c28x/epwm/epwm_0.obj" "./lib/pec-lib/drivers/ti_c28x/sci/sci_0.obj" "./lib/pec-lib/drivers/ti_c28x/sys/wd.obj" "./lib/pec-lib/drivers/ti_c28x/sys/flash.obj" "./lib/pec-lib/drivers/ti_c28x/sys/clock.obj" "./lib/pec-lib/drivers/ti_c28x/ti/280x/DSP280x_GlobalVariableDefs.obj" "./lib/pec-lib/drivers/ti_c28x/ti/2833x/DSP2833x_GlobalVariableDefs.obj" "./lib/pec-lib/drivers/ti_c28x/utils/timing/DSP28x_usDelay.obj" "./lib/pec-lib/utils/error_handling.obj" "./src/main.obj" "./src/DSP280x_CodeStartBranch.obj" -l"libc.a" "D:/Projects/gpu/lib/pec-lib/math/iqmath/IQmath.lib" "D:/Projects/gpu/lib/pec-lib/math/iqmath/IQmath_fpu32.lib" "D:/Projects/gpu/lib/pec-lib/debug/crosshairs/commros_28xx_full.lib" "D:/Projects/gpu/lib/pec-lib/build/cmd/2809_RAM_lnk.cmd" "D:/Projects/gpu/lib/pec-lib/build/cmd/DSP280x_Headers_nonBIOS.cmd" "D:/Projects/gpu/lib/pec-lib/build/cmd/F2809.cmd" 

  • Stian Soevik said:

    Hi, I want to have several linker command files in my project, which should be conditionally included based on predefined macros. However, when using one (e.g. #ifdef DSP28_2809) in the beginning of a file, it seems to not include the file regardless of DSP28_2809 being set.

    I'm not exactly clear how you are including or excluding linker command files from your project using the predefined macros.  Are you creating a master linker command file and based on the defined macros linking in other linker command files? If so, that could work but you would need to define the macros at the linker level instead of the compiler level.  

    If the --define option is passed to the shell cl2000 directly it will apply to the compiler, if it is passed after the -z (invoke linker) option, then it will apply to the linker. So the option is available under Compiler->Advanced Options -> Predefined Symbols (which applies to the compiler), as well as under Linker->Advanced Options->Command File Preprocessing (which applies to the linker). More information on the linker option can be found in the C2000 Assembly Language Tools Users Guide, section 7.4.7.

  • Thank you. I have defined the exact DSP in the project properties (DSP28_2809), and in a header file I will determine the "class":

    #if DSP28_2801 || DSP28_2802 || DSP28_2806 || DSP28_2808 || DSP28_2809 // TI 280x targets

    #include "ti/280x/DSP280x_Device.h"
    #define DSP28_280x 1

    Is there any ways to use this in the .cmd file (that is, only define DSP28_2809 once for both compiler and linker, and being able to use the DSP28_280x define in the cmd files)?

  • Stian Soevik said:
    Is there any ways to use this in the .cmd file (that is, only define DSP28_2809 once for both compiler and linker, and being able to use the DSP28_280x define in the cmd files)?

    Please see the section titled Link Command File Preprocessing in the C6000 assembly tools manual.  You have to specify -DDSP28_2809 both before and after -z on the command line.  If you build within CCS, then you have to put it in two places in the CCS build options dialog.

    Thanks and regards,

    -George

  • Thanks. What about using calculated macros from the compiler?

  • I'm not sure what you mean.  Please show me an example of what you are thinking about.

    Thanks and regards,

    -George

  • This is in a .h file:

    #if DSP28_2801 || DSP28_2802 || DSP28_2806 || DSP28_2808 || DSP28_2809

    #include "ti/280x/DSP280x_Device.h"
    #define DSP28_280x 1

    // TI 2833x targets
    #elif DSP28_28332 || DSP28_28334 || DSP28_28335

    #include "ti/2833x/DSP2833x_Device.h"
    #define DSP28_2833x 1

    // Undefined or unsupported targets
    #else

    #error No compatible device defined

    #endif

    Is it possible to use the DSP28_2809 macro in any .cmd file?

  • Stian Soevik said:
    Is it possible to use the DSP28_2809 macro in any .cmd file?

    There are only two ways that can happen.

    • On the linker command line, after the -z, appears the option --define=DSP28_2809.  Or ...
    • A source line in the command file, or some file #include'd by the command file, has this: #define DSP28_2809.

    Thanks and regards,

    -George

  • Thank you. AFAIK, new versions of CCS automatically includes all .cmd files in the project directories. Is it possible to disable this, and explicitly state which files to include? E.g. one file for 28335 and one file for 2809, where both files include the corresponding memory and GPIO peripheral maps.

  • Please see if this wiki article about how to exclude files from a CCS build is helpful.

    Thanks and regards,

    -George

  • Thank you, but this is what we're trying to avoid. We are creating a library that should be used on both 28335 and 2809 (and possibly other processors in the future), as these have many things in common. The developer specifies which processor he is working on as a compiler parameter, and then the correct linker file should be used.

    So, to clarify my question: Will CCS automatically include all .cmd-files it can "see", and is it not possible to disable this and explicitly include some .cmd-files instead?

  • Let me try to answer your questions based on my understanding of what you are asking. If I have misunderstood please let me know.

    You had asked earlier:

    Stian Soevik said:

     AFAIK, new versions of CCS automatically includes all .cmd files in the project directories. Is it possible to disable this, and explicitly state which files to include?

    When you create a new CCS project using the project wizard, in most cases a linker command file is added by default based on the device selected. If you are asking if it is possible to disable this automatic addition of a linker command file, then yes you can. In the New Project wizard, under Advanced Settings, change the Linker command file field from <automatic> to <none>. This will not add any linker command file to the project. After this you may add the files you wish, whether they be multiple .cmd files or a single master .cmd file which in turn adds other .cmd files based on a predefined symbol.

    If you only have one linker .cmd file to add to the project in place of the default, you can also use the Browse button next to the Linker command file field and browse directly to it.

    Does this help answer your question?

  • Thank you! Sorry if I am not clear enough. I meant that it seems like CCS will use all .cmd-files in the project, as long as it is in one of the folders added to it. If this is correct, it means that it's not possible to have a single master .cmd file which adds other files selectively, as the other files would already have been added.

  • Stian Soevik said:
    I meant that it seems like CCS will use all .cmd-files in the project, as long as it is in one of the folders added to it

    Yes that is correct. If the .cmd files are physically within the project folder (or in a sub-folder within the proejct folder) they will be automatically passed to the linker. However, if they are in a different folder (outside the project folder) or explicitly "excluded" from build, then they will not automatically be passed to the linker.

  • Thanks! I suppose I would include the "master" file in the project and keep the others outside, and include them with relative paths ("../linker/") etc.