I have a problem, I need to extern variuables from one file to another and I need to include a library. the problem is that when I include the library the compiler gives an error saying that the variables are undefined.
External file:
#include <stdio.h>
#include "PHY.h"
void InterruptHandler();
extern int flag;
extern long toSend;
extern int recieved;
void InterruptHandler()
{
//here i use the flag
}
The main:
#include <stdio.h>
#include "PHY.h"
void main()
{
int flag; // DETERMINATES CLOCK STATUS
int recieved;
long toSend; // THE DATA WE WANT TO SEND (for instance 0x12345678)
toSend = 0x12345678; // EXAMPLE
// .... here the code continues..
}
You can't make variables local to a function (for example, flag
in main()
) directly visible anywhere outside of the function, let alone reach them via extern
.
You need to move those local variables to outside of main()
, making them normal global variables. They'll be reachable via extern
in your "external" file.
Also, since the code suggests that you're handling interrupts in it, make those global variables that are accessed in the ISR volatile
. If you don't, changes to them may be invisible in the ISR or outside of it.