Search code examples
cgitmakefilegit-submodules

Manage two .C with same name but from differents submodules


I have an issue on a C project, where I integrate two different git submodules but coincidently they both have a stats.c and stats.h into them.

When I compile the whole project, it compiles until the linker tries to do its job.

It seems clear that we should not have twice files with same filenames. But how to manage this case? Because I can't really modify directly the file in both of the submodules, I mean I can't push commits into thoses repos.

Do you have some idea on how to implement a solution to be able to compile and keep track of both of the submodules?

I already tried the following :

  • renaming one of the c files : compilation and linking then works

Edit

Here is the linker message

[path]/arm-none-eabi/bin/ld: build/stats.o: in function `stat_init':  
[myproject]/Lib/stats.c:57: multiple definition of \`stat_init\'; build/stats.o:[myproject]/Lib/stats.c:57: first defined here

From my understanding it's not an issue from the .h but from the two .c that have the same name (here stats.c). For me the linker tries twice to link the same .o which was either overwritten or ignored during the compilation of the second .c


Solution

  • Finally I was able to solve this issue : by renaming one of the .C. For any other user having the same issue, another solution could have been to adapt the makefile to avoid two .o having the same name.

    Hope this could help!