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.

Conditional inclusion in project build of various .lib files?

Guru 15580 points

Not sure if this is a compiler question or ccs question....but:

I would like to link one of several different versions of a .lib file into my project build, based on a single compile switch (ie "ifdef SWITCH_1"). The various .lib files reside in directories outside of my workspace. Is there an easy way to do this?

Thx,

MikeH

 

  • Recent versions of the compiler support C-style preprocessing within the linker command file.  What version of the compiler (not CCS) are you using?

  • I believe it is V7.0.3. However, I am using DSP/BIOS so I don't have a separate linker .cmd file.

  • This feature was introduced in C6000 compiler version 6.1.0, so it should be available.  You can have as many linker command files as you need; you should be able to create a separate one referring to just the libraries you wish to conditionally include.

  • Thanks Arch. I'll give it a try.

    Thx,

    MikeH

     

  • Arch,

    Well, I must be doing something wrong.

    >> WARNING: invalid compiler option --l (ignored)

    >> WARNING: invalid compiler option --l (ignored)

    Fatal error: could not open source file "C:\Users\Mike\TI"

    1 fatal error detected in the compilation of "C:\Users\Mike\TI".

    Compilation terminated.

    I created a file called mylibraries.cmd and included it in the Build->Tool Settings->Command Files.

    My .cmd file looks like this:

    #ifdef RELEASE_VERSION

    # ifdef LIBRARY_VERSION_71

    -l C:\Users\Mike\TI Workspaces\LIBRARY Archives\libLIBRARY71_DSP\Release\libLIBRARY71_DSP.lib

    # endif

    # ifdef LIBRARY_VERSION_81

    # endif

     

    # ifdef LIBRARY_VERSION_91

    # endif

     

    # ifdef LIBRARY_VERSION_100

    # endif

     

    # ifdef LIBRARY_VERSION_110

    # endif

     

    # ifdef LIBRARY_VERSION_111

    # endif

     

    #elif defined (DEBUG_VERSION)

     

    # ifdef LIBRARY_VERSION_71

    -l = C:\Users\Mike\TI Workspaces\LIBRARY Archives\libLIBRARY71_DSP\Debug\libLIBRARY71_DSP.lib

    # endif

     

    # ifdef LIBRARY_VERSION_81

    # endif

     

    # ifdef LIBRARY_VERSION_91

    # endif

     

    # ifdef LIBRARY_VERSION_100

    # endif

     

    # ifdef LIBRARY_VERSION_110

    # endif

     

    # ifdef LIBRARY_VERSION_111

    # endif

     

    Do you see anything obviously wrong here?

    Thx,

    MikeH

     

  • You are passing the linker command file in a way that the compiler think it is a compiler command file.

    See the following post:

    http://e2e.ti.com/support/development_tools/compiler/f/343/p/107118/377842.aspx#377842

  • To add a linker command file to a CCS project you can do it one of these ways:

    1) Project Build Properties->C/C++ Build->Linker->File Search Path:  Add the linker command file to the "Include library file or command file as input" option, or
    2) Add the linker command file directly to the project by right-clicking on project and choosing Add Files or Link Files (depending on whether you want to copy it to workspace or just link to it from a different location).

  • Aarti,

    Aarti said:
    Add the linker command file directly to the project by right-clicking on project and choosing Add Files or Link File

    I have done this and am able to compile and link without errors. However, my main goal was to selectively include a .lib file based on my selecting a specific compiler switch (see my original post above). After adding the linker .cmd file (as shown above) I now get linker errors saying that the linker has unresolved symbols, which tells me that the conditional #define and -l directives in the .cmd are not being processed properly. Or (more likely) I have not formatted them properly.

    Am I correct is assuming that I can include:

    #ifdef LIBRARY_VERSION_71

    -l library_v71.lib

    in my .cmd file and it will cause library_v71.lib to be used by the linker if I #define LIBRARY_VERSION_71 in my .c code?

    Thx,

    MikeH

     

     

  • MikeH said:

    Am I correct is assuming that I can include:

    #ifdef LIBRARY_VERSION_71

    -l library_v71.lib

    in my .cmd file and it will cause library_v71.lib to be used by the linker if I #define LIBRARY_VERSION_71 in my .c code?

    [/quote]

    The linker doesn't see any #define in your C code.  You have to additionally pass an option to the linker defining that name.  Here are the relevant options:

    Command File Preprocessing Options:
      --define=name=value             Pre-define preprocessor macro _name_ to _value_
      --undefine=name                 Undefine preprocessor macro _name_
      --disable_pp                    Don't use C preprocessor for command files
    
  • Arch,

    Archaeologist said:
    --define=name=value

    OK. I will give this a try.

    Now I need to do a similar sort of thing for the include paths of the libraries. Since the function call format is different for the various .lib versions, I need to point to a different .h file. I have tried adding the following .cmd file to Build Properties->Command Files, but get errors:

    #ifdef RELEASE_VERSION

     

    #ifdef LIB_VERSION_71

    -i "C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Release\libLIB"

    #endif

     

    #ifdef LIB_VERSION_81

    -i "C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB"

    #endif

     

    # ifdef LIB_VERSION_91

    # endif

     

    # ifdef LIB_VERSION_100

    # endif

     

    # ifdef LIB_VERSION_110

    # endif

     

    # ifdef LIB_VERSION_111

    # endif

     

    #endif

     

    #ifdef DEBUG_VERSION

     

    # ifdef LIB_VERSION_71

    -i "C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Release\libLIB"

    # endif

     

    # ifdef LIB_VERSION_81

    -i "C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB"

    # endif

     

     

    # ifdef LIB_VERSION_91

    # endif

     

    # ifdef LIB_VERSION_100

    # endif

     

    # ifdef LIB_VERSION_110

    # endif

     

    # ifdef LIB_VERSION_111

    # endif

     

    #endif

    Which produces the following errors:

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: error: expected a declaration

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    "C:\Users\Mike\TI Workspaces\AMX2\DSP_LIB\libLIB_paths.inc", line 8: warning: unrecognized character escape sequence

    Which tells me something is wrong with the format of my .cmd file. Can you provide some guidance?

    Thx,

    MikeH

  • You are again getting error messages from the compiler, not the linker, so this command file has the same problem as the previous one.  Perhaps the file name extension is reserved?

  • Or is this really intended to be a compiler command file?  If so, preprocessing is not supported for the compiler command file.  You should create a new header file that conditionally includes the appropriate header file using the absolute path, and just include that.

  • Arch,

    Archaeologist said:
    preprocessing is not supported for the compiler command file.

    Yes, sorry for not being clear. I was attempting to use pre-processing directives in a COMPILER .cmd file. It obviously does not work properly.

    Archaeologist said:
    You should create a new header file that conditionally includes the appropriate header file using the absolute path, and just include that.

    Of course! That makes sense.

    Unfortunately (back now to the linker .cmd file) I am running into problems trying to implement your suggestion of:

    --define=name=value

    Per the User Guide, here is what I have done at the top of my (linker) .cmd file:

     

    -define=RELEASE_VERSION

    -define=LIB_VERSION_81 

     

    #ifdef RELEASE_VERSION

     

    # ifdef LIB_VERSION_71

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Release\libLIB71_DSP.lib

    # endif

     

    # ifdef LIB_VERSION_81

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB81_DSP_MH.lib

    # endif

     

    # ifdef LIB_VERSION_91

    # endif

     

    # ifdef LIB_VERSION_100

    # endif

     

    # ifdef LIB_VERSION_110

    # endif

     

    # ifdef LIB_VERSION_111

    # endif

    #endif

     

    #ifdef DEBUG_VERSION

     

    # ifdef LIB_VERSION_71

    -l = C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Debug\libLIB71_DSP.lib

    # endif

     

    # ifdef LIB_VERSION_81

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB81_DSP_MH.lib

    # endif

     

     

    # ifdef LIB_VERSION_91

    # endif

     

    # ifdef LIB_VERSION_100

    # endif

     

    # ifdef LIB_VERSION_110

    # endif

     

    # ifdef LIB_VERSION_111

    # endif

     

    #endif

    .....but get the following errors

     

    <Linking>

    "../libLIB_libraries.cmd", line 1: error: invalid option:

       -define=RELEASE_VERSION

    "../libLIB_libraries.cmd", line 2: error: invalid option:

       -define=LIB_VERSION_81

    Any ideas?

     

     

    Thx,

    MikeH

  • MikeH said:
    -define=RELEASE_VERSION
    -define=LIB_VERSION_81 

    Two leading dashes:

    --define=RELEASE_VERSION
    --define=LIB_VERSION_81
  • Archaeologist said:
    Two leading dashes:

    Yes, tried that too....

     

    <Linking>

    "../libLIB_libraries.cmd", line 1: error: cannot find file "RELEASE_VERSION"

    "../libLIB_libraries.cmd", line 2: error: cannot find file "LIB_VERSION_81"

    The user's guide is quite thin in this area.....

     

  • What are the first two lines of "libLIB_libraries.cmd", exactly?

  •  

    Arch,

    Archaeologist said:
    What are the first two lines of "libLIB_libraries.cmd", exactly?

    These are the first two lines of libLIB_libraries.cmd

    --define = RELEASE_VERSION

    --define = LIB_VERSION_81

    In fact, here is the entire file

     

    --define = RELEASE_VERSION

    --define = LIB_VERSION_81

     

    #ifdef RELEASE_VERSION

     

    # ifdef LIB_VERSION_71

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Release\libLIB71_DSP.lib

    # endif

     

    # ifdef LIB_VERSION_81

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB81_DSP_MH.lib

    # endif

     

    # ifdef LIB_VERSION_91

    # endif

     

    # ifdef LIB_VERSION_100

    # endif

     

    # ifdef LIB_VERSION_110

    # endif

     

    # ifdef LIB_VERSION_111

    # endif

    #endif

     

    #ifdef DEBUG_VERSION

     

    # ifdef LIB_VERSION_71

    -l = C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Debug\libLIB71_DSP.lib

    # endif

     

    # ifdef LIB_VERSION_81

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB81_DSP_MH.lib

    # endif

     

     

    # ifdef LIB_VERSION_91

    # endif

     

    # ifdef LIB_VERSION_100

    # endif

     

    # ifdef LIB_VERSION_110

    # endif

     

    # ifdef LIB_VERSION_111

    # endif

     

    #endif

    MikeH

     

     

     

     

  • MikeH said:

    --define = RELEASE_VERSION

    --define = LIB_VERSION_81

    Remove the spaces around the equal signs.  Alternatively, you can remove the '=' altogether and leave whitespace between --define and RELEASE_VERSION.

    I think the spaces between "#" and "ifdef" are OK, but I'm not 100% sure.

  • Archaeologist said:
    Remove the spaces around the equal signs

    That worked!

    Archaeologist said:
    I think the spaces between "#" and "ifdef" are OK, but I'm not 100% sure.

    The seem to work OK.

    However, the linker does not like the spaces in my path names.

    <Linking>

    error: cannot find file "C:\Users\Mike\TI"

    "../libLIB_libraries.cmd", line 18: error: cannot find file "Workspaces\LIB"

    "../libLIB_libraries.cmd", line 18: error: cannot find file

       "Archives\libLIB81_DSP_MH\Release\libLIB81_DSP_MH.lib"

    error: errors encountered during linking; "DSP_LIB.out" not built

    Note the path name below:

    --define RELEASE_VERSION

    //--define DEBUG_VERSION

     

    //--define LIB_VERSION_71

    --define LIB_VERSION_81

    //--define LIB_VERSION_91

    //--define LIB_VERSION_100

    //--define LIB_VERSION_111

    //--define LIB_VERSION_113

     

    #ifdef RELEASE_VERSION

     

    # ifdef LIB_VERSION_71

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB71_DSP\Release\libLIB71_DSP.lib

    # endif

     

    # ifdef LIB_VERSION_81

    -l C:\Users\Mike\TI Workspaces\LIB Archives\libLIB81_DSP_MH\Release\libLIB81_DSP_MH.lib

    # endif

    I can't change my path names. How can I make the linker more tolerant of the spaces?

    Thx,

    MikeH

     

  • You need double quotes around any path with special characters, including space.  I could have sworn you had the quotes in this file already...

  • Archaeologist said:
    I could have sworn you had the quotes in this file already...

    ....and I could have sworn that I already tried that. But, after adding the quote around the path.....all is working!!

    THIS DIALOG WOULD MAKE A GREAT WIKI PAGE....:) (ie. conditional includes of various library files via compile/link switch).

    Thanks for helping me chase this down.

    MikeH