I added bms_module.c file modues folder and included in CMakeLists. Corresponding bms_events.c and bms_events.h files are placed in events folder. The project working well.
Then I added more files bms.c and bms.h, serial.c and serial.h. The dependency graph is as :
bms_module.c -> bms.c and serial.c
bms.c-> serial.c
The some variables and functions declared in bms.h and serial.h are required in bms_module.c, while some variables and functions of serial.h are required in bms.c. I tried various methods to place these four files of (bms.c, bms.h, serial.c, serial.h) and declare in CMakeLists accordingly. I facing the issue of multiple definitions, as below.
1. What is rule to place files in zephyr ?
2. Why including .h file only in multiple files causes multiple definitions error while theoretically declaration in C can be as many times but definition only in one file. I following this rule, even then the error occurs.
3. If the variables of a .h file are used in multiple .c files, how zephyr handles that ? Zephyr creates .obj file for each .c file. So, multiple definitions appear in ore than one .obj file ? How to handle this situation ?
c:/firmware/firmware/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bms_module.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:36: multiple definition of `max_mv_cell'; app/libapp.a(bms.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:36: first defined here
c:/firmware/firmware/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bms_module.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:34: multiple definition of `current_msg'; app/libapp.a(bms.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:34: first defined here
c:/firmware/firmware/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bms_module.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:33: multiple definition of `soc_msg'; app/libapp.a(bms.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:33: first defined here
c:/firmware/firmware/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bms_module.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:32: multiple definition of `packv_msg'; app/libapp.a(bms.c.obj):C:\firmware\firmware\firmware\src\modules\bms\bms.h:32: first defined here