Global variable - how to?

Description

After months of procrastinating, I have finally started to connect my LVGL app to live data.
My .ino file includes the LVGL touch and display driver as well as my CAN driver and application that fetches the data.

My LVGL app is built in .c file and is included in the main .ino file.

In the main .ino file (lets just call it main.ino), I have a float declared and initialised.
I want the lvgl .c file (lets call it app.c) to read that float and pass it to a widget.
For this I have created a header file called global_vars.h and I have declared it in there, but for some reason the compiler shouts that its either declared twice or it does not contain a name type (depending on where I include the header file or it I declare extern etc)

Hoping someone can help as I am getting more and more confused the more I Google this topic :sweat_smile:

What LVGL version are you using?

7.10
Arduino IDE 1.83 (Teensyduino 1.53)
Teensy 4.1

What do you want to achieve?

Set a variable value in a main .ino file and have LVGL read it in a separate app .c file

What have you tried so far?

Code to reproduce

main.ino

#include "global_vars.h"
#include "app.c"
void setup() {
  globalVar = 1.1;
}

void loop() {
  // put your main code here, to run repeatedly:
}

global_vars.h

#ifndef GLOBAL_VARS_H
#define GLOBAL_VARS_H
extern float globalVar;

#endif

app.c

#include "global_vars.h"
float abc = globalVar;

You need to define global var in a cpp file somewhere still. extern globalsVar just says you have a reference to some external variable somewhere. It doesn’t actually define the variable. You should have a globals.c that has float globalVar; in it.

Thank you Scott!
I will give that a try tomorrow and report back

@scottandrew that worked, thank you!