dlktdr / HeadTracker

This project is built to record the orientation a FPV headset to allow the camera on your RC to follow your head movements.
GNU General Public License v3.0
378 stars 90 forks source link

fix west build time multiple define linker error `log_const_flash` #177

Closed aphor closed 3 months ago

aphor commented 3 months ago

this linker error appears at build time:

/opt/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/libzephyr.a(flash_util.c.obj):/home/jeremy/src/HeadTracker.git/firmware/zephyr/zephyr/drivers/flash/flash_util.c:14: multiple definition of `log_const_flash'; app/libapp.a(soc_flash.cpp.obj):/home/jeremy/src/HeadTracker.git/firmware/src/src/soc_flash.cpp:35: first defined here

from zephyr/include/zephyr/logging/log.h

/**
 * @brief Create module-specific state and register the module with Logger.
 *
 * This macro normally must be used after including <zephyr/logging/log.h> to
 * complete the initialization of the module.
 *
 * Module registration can be skipped in two cases:
 *
 * - The module consists of more than one file, and another file
 *   invokes this macro. (LOG_MODULE_DECLARE() should be used instead
 *   in all of the module's other files.)
 * - Instance logging is used and there is no need to create module entry. In
 *   that case LOG_LEVEL_SET() should be used to set log level used within the
 *   file.
 *
 * Macro accepts one or two parameters:
 * - module name
 * - optional log level. If not provided then default log level is used in
 *  the file.
 *
 * Example usage:
 * - LOG_MODULE_REGISTER(foo, CONFIG_FOO_LOG_LEVEL)
 * - LOG_MODULE_REGISTER(foo)
 *
 *
 * @note The module's state is defined, and the module is registered,
 *       only if LOG_LEVEL for the current source file is non-zero or
 *       it is not defined and CONFIG_LOG_DEFAULT_LEVEL is non-zero.
 *       In other cases, this macro has no effect.
 * @see LOG_MODULE_DECLARE
 */
#define LOG_MODULE_REGISTER(...)                                        \
        COND_CODE_1(                                                    \
                Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__),                  \
                (_LOG_MODULE_DATA_CREATE(GET_ARG_N(1, __VA_ARGS__),     \
                                      _LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
                () \
        )                                                               \
        LOG_MODULE_DECLARE(__VA_ARGS__)

/**
 * @brief Macro for declaring a log module (not registering it).
 *
 * Modules which are split up over multiple files must have exactly
 * one file use LOG_MODULE_REGISTER() to create module-specific state
 * and register the module with the logger core.
 *
 * The other files in the module should use this macro instead to
 * declare that same state. (Otherwise, LOG_INF() etc. will not be
 * able to refer to module-specific state variables.)
 *
 * Macro accepts one or two parameters:
 * - module name
 * - optional log level. If not provided then default log level is used in
 *  the file.
 *
 * Example usage:
 * - LOG_MODULE_DECLARE(foo, CONFIG_FOO_LOG_LEVEL)
 * - LOG_MODULE_DECLARE(foo)
 *
 * @note The module's state is declared only if LOG_LEVEL for the
 *       current source file is non-zero or it is not defined and
 *       CONFIG_LOG_DEFAULT_LEVEL is non-zero.  In other cases,
 *       this macro has no effect.
 * @see LOG_MODULE_REGISTER
 */
#define LOG_MODULE_DECLARE(...)                                               \
        extern const struct log_source_const_data                             \
                        Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__));     \
        extern struct log_source_dynamic_data                                 \
                        LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__));     \
                                                                              \
        static const struct log_source_const_data *                           \
                __log_current_const_data __unused =                           \
                        Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) ?               \
                        &Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) :   \
                        NULL;                                                 \
                                                                              \
        static struct log_source_dynamic_data *                               \
                __log_current_dynamic_data __unused =                         \
                        (Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) &&             \
                        IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ?           \
                        &LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)) :   \
                        NULL;                                                 \
                                                                              \
        static const uint32_t __log_level __unused =                          \
                                        _LOG_LEVEL_RESOLVE(__VA_ARGS__)
dlktdr commented 3 months ago

I wonder if it's just better to rename it from "flash" to maybe soc_flash. So the internal zephyr log module flash messages

https://github.com/ZephyrRTOS/zephyr/blob/768b8bbca30ab78f2fed33272b695434288727d3/drivers/flash/flash_util.c#L14

can't be confused with the HT flash log messages.