cancel
Showing results for 
Search instead for 
Did you mean: 

Extern variable error

olifanten
Associate

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!

1 REPLY 1

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..