Duplicate symbol in .o error

I have a C project that has worked out well, and now I want to break the program into three files, to make the functions reusable.

In doing so, I found that I get linker errors. The abc.c file compiles cleanly. But compiling abc_example.c gives an error like this:


duplicate symbol '_MAX_VALUE' in:
    /private/var/folders/abc_example-633d99.o
    /Users/me/programs/abc.o
ld: 1 duplicate symbols
clang: error: linker command failed with exit code 1 (use -v to see invocation)



The line in abc.h is:

   int MAX_VALUE = 0;


I found that this problem stems from not being able to initialize variables in a .h file. (Is this new? I remember being able to do this.) The solution is to have MAX_VALUE in both the abc.h and abc.c files, as follows.

  extern int MAX_VALUE;      // in the abc.h file
  int MAX_VALUE = 0;         // in the abc.c file

After this, abc_exmple.c compiles and links cleanly.
-MCW, Dec 2025