2024-07-21 03:20 AM
Hello,
I'd like to use some extern variables in my code, but I always get the error "undefined reference to ..." and I can't find what I am doing wrong.
In the timer.h file I declare the variable as:
extern volatile uint8_t start_adc_flag;
I included this file in both main.c and stm32g4xx_it.c.
I then define the variable in main.c:
volatile uint8_t start_adc_flag = 0;
and use it in stm32g4xx_it.c:
if(start_adc_flag == 0){
...
}
The error I get is that the variable is not defined in stm32g4xx_it.c:
/Core/Src/stm32g4xx_it.c:273: undefined reference to `start_adc_flag'
Thank you in advance for your help!
2024-07-21 11:43 AM
Compiler evidently doesn't think the variable is defined, check that you're looking at the right files, and it's including what you expect.
Put the extern in the stm32g4xx_it.c