C-Code Library Configuration

Organizing Shared Implementations with a Library Folder

If multiple ECU functions use the same C or header files, you can store these shared files in a separate library folder.

The library folder can be placed outside the main input directory and referenced through the libraryPath setting in the C-Code configuration file.

Example directory structure:

└── ECU_SW_XYZ
    ├── Function1
    │   └── function_1_implementation.c
    ├── Function2
    │   └── function_2_implementation.c
└── lib
    ├── shared_util.c
    └── shared_util.h

Example: Using a Shared Library

The following example shows how two ECU functions use the same shared library.

Library Header (lib/shared_util.h)
#ifndef SHARED_UTIL_H
#define SHARED_UTIL_H

int addValues(int a, int b);

#endif
Library Source (lib/shared_util.c)
#include "shared_util.h"

int addValues(int a, int b) {
    return a + b;
}
Function 1 (Function1/function_1_implementation.c)
#include "shared_util.h"

int computeMotorSpeed(void) {
    int base = 100;
    int offset = 20;

    // Library function used here
    return addValues(base, offset);
}
Function 2 (Function2/function_2_implementation.c)
#include "shared_util.h"

int computePower(void) {
    int voltage = 12;
    int current = 3;

    // Same library function used here
    return addValues(voltage, current);
}

Library Configuration in EHANDBOOK

Without configuring the libraryPath, EHANDBOOK Container-Build cannot resolve shared functions. These functions are shown as black boxes in the interactive model.

EHANDBOOK without Library Configuration

After configuring the libraryPath, EHANDBOOK Container-Build resolves the shared functions and displays the complete function call hierarchy.

EHANDBOOK with Library Configuration

Using a shared library provides the following benefits:

  • Shared functions are resolved correctly.

  • Common code is stored in one place and can be reused by multiple ECU functions.

  • Duplicate code is avoided.