linking FAQ

How can I add a #define to the linker command file in BCLIDE?

If the #define is not already present in a header file or C program module, create a new header file for it and list the file in the Include Files list. Select the Include Files tab and click Add File. In the Open dialog, choose the file and click OK.

It is also possible to specify #define values in the COMMAND= line in the Options tab in BCLIDE. This value is passed through to the compiler to use during code generation:


Please note:

  • This setting only applies to code generation during linking. Compiling C code into object files must not rely on this definition.

  • If VALUE has any embedded spaces, you must enclose it in quotes.

  • If VALUE has any embedded semicolon characters, you must enclose it in quotes.


I need to combine one eTPU executable into another eTPU executable. How can I do this?

Use the BClink directive ETPUIMAGE. During this linking, the specified executable will be linked in to the final executable. eTPU_C will perform checks to prevent conflicts between the two executables.

  1. Export the first executable with the following eTPU_C host interface macro in the first linker command file.
    #pragma write msc, ( ::ETPUcode );
  2. Import the first executable during linking for the second executable, using the ETPUIMAGE directive instead of an OBJECT or LIBRARY directive.

    Export a new executable and MISC value for the host compiler's use.

    // Output a code image of both links
    #pragma write q, (const u32 etpu_code[] = { ::ETPUcode32};);
    // Create the combined MISC value
    #pragma write q, ( #define MISC ::ETPUmisc );
    // Read the code image of the first link and combine it with the second link
    ETPUIMAGE= etpu_a_CPU.msc

The compiler isn't obeying my customized layout of memory resources and functions. What's wrong?

Make sure you're supplying all #pragma directives to BClink. BClink uses the same device configuration information during linking as the compiler does during Absolute Code Mode. BClink performs a final code generation pass over your object files, and needs this information to allocate variables and program code locations.

Either organize the directives in a header file that you can #include in the linker command file, or put the directives in the file directly. In BCLIDE, create a new header file and list it under Project|Properties, in the Include Files list under the Linker tab.


What is Absolute Code Mode?

Absolute Code Mode in Byte Craft Limited compilers generates executable code from the compiler without a linking step. Absolute Code Mode still allows you to select object code from libraries and include it as part of an application.

The compiler will read in any functions that are referenced in the eTPU_C program and are available in a library file. Simply #include the library's header file at the top of a program module, or (if there is no header) #include the library itself at the end of the main program.

For example, consider a program that uses spark, fuel, cam, and crank ETPU_functions. These statements will select the referenced eTPU functions from engine.lib and assign them to individual eTPU function numbers.

engine.lib members

#pragma ETPU_function spark @ 2;
#pragma ETPU_function fuel  @ 3;
#pragma ETPU_function cam   @ 4;
#pragma ETPU_function crank @ 5;

#include <engine.h>

When creating library files, enclose the code in #pragma library and #pragma endlibrary statements. These signal the compiler to read into the program only those functions that are referenced in the main program. Compile the library sources to an object file, and rename the object file with a .lib extension.

The significance of the .lib extension: .lib files are automatically included every time a .h file is #included in a source program. In all cases, library files should be renamed from .obj to .lib.


What should I know about linking?

Linking was most useful in the age of limited computing resources, on self-hosting systems. Since our customers are cross-developing, and compiling resources are effectively unlimited (given the typical sizes of the embedded executables they create), linking has declined in importance.

We advocate Absolute Code Mode, a single compile-and-link step. Absolute Code Mode simply compiles the main C module to an executable, as opposed to an object file.

In fact, choosing to use object files can raise some interesting consequences:

  • Our compilers perform application-level optimization, to allow the compiler to pare the executable down as much as possible. This requires that #pragma directives from the device header file be present (or #included) in the linker command file, and that preprocessor directives can also appear there.
  • When compiling to object, the compiler will raise an error when #included files are missing. It will do this even when the #include is discounted by preprocessor statements (conditional compilation).