Skip to main content
Visitor II
July 21, 2024
Question

Extern variable error

  • July 21, 2024
  • 1 reply
  • 1425 views

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

    Tesla DeLorean
    Guru
    July 21, 2024

    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 VenmoUp vote any posts that you find helpful, it shows what's working..