For gcc, you can use the -fno-common
flag to turn this into an error.
The gcc documentation explains what's happening
-fno-common
In C code, controls the placement of uninitialized global variables. Unix C compilers have traditionally permitted multiple
definitions of such variables in different compilation units by
placing the variables in a common block. This is the behavior
specified by -fcommon, and is the default for GCC on most targets.
On
the other hand, this behavior is not required by ISO C, and on some
targets may carry a speed or code size penalty on variable references.
The -fno-common option specifies that the compiler should place
uninitialized global variables in the data section of the object file,
rather than generating them as common blocks. This has the effect that
if the same variable is declared (without extern) in two different
compilations, you get a multiple-definition error when you link them.
See also Tentative definitions in C99 and linking