Thanks gfvalvo,
I got it to work by declaring and defining the global variables in the same cpp file, and using the extern keyword in the other files that reference a global variable.
Apparently my original problem occurred because I declared and defined the global variables in the header file, which was included in multiple cpp files. That is why I got the multiple definition errors.
Here is the final code (I added a define_global_var.cpp file to the original four files):
/* FILE: multi_file.ino */
#include "multi_file.h"
void setup() {
}
void loop() {
fnc_1();
fnc_2();
}
/* FILE: multi_file.h */
#ifndef multi_file_h
#define multi_file_h
#include "Arduino.h"
extern byte var_1;
extern byte var_2;
void fnc_1( void );
void fnc_2( void );
#endif
/* FILE: define_global_var.cpp
*
* Declares AND define global variables, which is normally done in the ino file.
*/
#include "Arduino.h"
byte var_1 = 0;
byte var_2 = 0;
/* FILE: fnc_1.cpp */
#include "multi_file.h"
void fnc_1( void ) {
var_1 = 1;
}
/* FILE: fnc_2.cpp */
#include "multi_file.h"
void fnc_2( void ) {
var_2 = 1;
}