[SOLVED] Weak variables of global file scope linker error
So I'm trying to gain greater understanding on the STM32 tools on a project that I've inherited. I'm noticing that there are weak variables that are of global scope to a given file that are defined in multiple files such as follows:
main.c:
int g;other.c
int g;I would expect that when the project is linked that one of the variable is chosen and no linker errors are give, however, a linker error appears as if the variables are strong. Something along the line of the following:
.../main.o:/project/other.c:2: multiple definition of `g'; .../main.o:/project//main.c:2: first defined here
I have seen that there are compiler switches in gcc "-fno-common" that can affect if this error is thrown with weak variables but I can't seem to find this turned on in my project.
The real issue at play here is that when a colleague builds the project in Windows from the same git repository they do not encounter this issue, but I see it when I compile in Linux. Further, this is a massive legacy project that generates over 400 of these link errors. Though I am able to resolve the issues by making a single weak variable and making all other instants extern, I first would like to understand the code before potentially breaking it.
If there is anyone that can help resolve this issue I would appreciate it.
Jacob
