You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have a few unit test suites that are all totally implemented in header files. I understand that each function must have LOG_MODULE_DELCARE and in a source file LOG_MODULE_REGISTER must be called once in order to use the logging module in these test suites.
I am trying to register a logging module for each test suite in the same source (main.cpp) using the code shown below.
I intend to transition my project from calling printk directly to using the Logging Module and there are quite a few header only implementations, so if possible, I'd like to avoid creating source files to register logging modules like I have for the test suites.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I have a few unit test suites that are all totally implemented in header files. I understand that each function must have LOG_MODULE_DELCARE and in a source file LOG_MODULE_REGISTER must be called once in order to use the logging module in these test suites.
I am trying to register a logging module for each test suite in the same source (main.cpp) using the code shown below.
#include <zephyr/logging/log.h> LOG_MODULE_REGISTER(main); LOG_MODULE_REGISTER(a_sensor_tests); LOG_MODULE_REGISTER(b_sensor_tests);
and get the following build error.
In file included from ..../UnitTests/main.cpp:8: /zephyr/include/zephyr/logging/log.h:405:17: error: redefinition of ‘const log_source_const_data* __log_current_const_data’ 405 | __log_current_const_data __unused = \ | ^~~~~~~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:370:9: note: in expansion of macro ‘LOG_MODULE_DECLARE’ 370 | LOG_MODULE_DECLARE(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~ ..../UnitTests/main.cpp:47:1: note: in expansion of macro ‘LOG_MODULE_REGISTER’ 47 | LOG_MODULE_REGISTER(b_sensor_tests); | ^~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:405:17: note: ‘const log_source_const_data* __log_current_const_data’ previously defined here 405 | __log_current_const_data __unused = \ | ^~~~~~~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:370:9: note: in expansion of macro ‘LOG_MODULE_DECLARE’ 370 | LOG_MODULE_DECLARE(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~ ..../UnitTests/main.cpp:46:1: note: in expansion of macro ‘LOG_MODULE_REGISTER’ 46 | LOG_MODULE_REGISTER(main); | ^~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:411:17: error: redefinition of ‘log_source_dynamic_data* __log_current_dynamic_data’ 411 | __log_current_dynamic_data __unused = \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:370:9: note: in expansion of macro ‘LOG_MODULE_DECLARE’ 370 | LOG_MODULE_DECLARE(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~ ..../UnitTests/main.cpp:47:1: note: in expansion of macro ‘LOG_MODULE_REGISTER’ 47 | LOG_MODULE_REGISTER(b_sensor_tests); | ^~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:411:17: note: ‘log_source_dynamic_data* __log_current_dynamic_data’ previously defined here 411 | __log_current_dynamic_data __unused = \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:370:9: note: in expansion of macro ‘LOG_MODULE_DECLARE’ 370 | LOG_MODULE_DECLARE(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~ ..../UnitTests/main.cpp:46:1: note: in expansion of macro ‘LOG_MODULE_REGISTER’ 46 | LOG_MODULE_REGISTER(main); | ^~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:417:31: error: redefinition of ‘const uint32_t __log_level’ 417 | static const uint32_t __log_level __unused = \ | ^~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:370:9: note: in expansion of macro ‘LOG_MODULE_DECLARE’ 370 | LOG_MODULE_DECLARE(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~ ..../UnitTests/main.cpp:47:1: note: in expansion of macro ‘LOG_MODULE_REGISTER’ 47 | LOG_MODULE_REGISTER(b_sensor_tests); | ^~~~~~~~~~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:417:31: note: ‘const uint32_t __log_level’ previously defined here 417 | static const uint32_t __log_level __unused = \ | ^~~~~~~~~~~ /zephyr/include/zephyr/logging/log.h:370:9: note: in expansion of macro ‘LOG_MODULE_DECLARE’ 370 | LOG_MODULE_DECLARE(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~ ...../UnitTests/main.cpp:46:1: note: in expansion of macro ‘LOG_MODULE_REGISTER’ 46 | LOG_MODULE_REGISTER(main);
The best solution I've had to the issue is creating a source file for each test suite that has the following
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(b_sensor_tests)
I intend to transition my project from calling printk directly to using the Logging Module and there are quite a few header only implementations, so if possible, I'd like to avoid creating source files to register logging modules like I have for the test suites.
Beta Was this translation helpful? Give feedback.
All reactions