I am a C newbie so I hope I am using the terms below correctly:

I have Ubuntu 20.04; CMAKE 3.22.1 GCC 9.2.1 ARM-none-eabi-GCC;

VScode is IDE.

I wrote a C library for the RP2040 and a SPI IC a few months ago.
The library required a buffer; so i declared a global array in the library's .h file.

The library along with test code in main.c compiled OK at that time.

I could call functions from the library in main.c without issue.

However A few weeks ago I went to use the library again and got multiple declaration errors for the arrays declared earlier.

I made no code changes.....but What used to work no longer worked.

I fixed it by making the arrays in the library extern and then adding the same arrays declarations, without "extern" keyword, to main.c

with those changes the whole thing compiles OK again

but the library seemed more portable before.

I am not sure what changed here?

Here An example of code which compiles and runs in GDB online without error. This is a extremely simplified version of the library but the same general idea.

####################
main.c
####################
Code:
#include <stdio.h>
#include "ext1.h"
 
int main()
{
 mult_me(6);
 printf("value of c is: %d",c[0]);
}

####################
ext1.h
####################
Code:
//global array
int c[1];
 
int mult_me(int x);

####################
ext1.c
####################

Code:
#include "ext1.h"
 
int mult_me(int x)
{
    c[0] = 7*x;
    
}
####################

If i run this same code on the Ubuntu/CMAKE/arm-none-eabi setup it throws multiple definition" issues for the variable c found in main.c

I hope more experienced programmers can follow what I am saying.....

I'd like to know why what used to compile OK suddenly stopped working. I assume it was an update of some kind but can't figure out what did it.

Anyone who can shed some light on this, I'd be very grateful.

Thank you