I am running into a problem with compiling in VScode and not when in Visual Studio.
I have a header file config.h
in the include folder in my project. Please note I have added build_flags = -I include
to platformio.ini. In config.h
I need to make some declarations for a select number of global variables that I need. Everything else is done with pointers, etc.
The problem I have is two fold.
- When declaring a variable for example
int myVar
in config.h I get a multiple declaration error. Why? - I can declare the variable as
extern int myVar
. But then I need to redeclare the variable myVar in a .cpp file, like main.cpp. How is this best done?
Ultimately, how can I declare a global variable in a header, include that header in several other files and then use the variable globally? (This is primarily aimed at creating queues and semaphores)