Please see the below example code for the use of "extern". When I use the extern keyword in my code, I get a compilation error. Please suggest a solution for the problem.
#include<iostream>
extern int x;
extern int y;
extern int z;
int main(){
x = 10;
y = 15;
z = (x>y ? x: y);
std::cout<<z;
return 0;
}
Error message:
example8.cpp:(.rdata$.refptr.z[.refptr.z]+0x0): undefined reference to `z';
example8.cpp:(.rdata$.refptr.y[.refptr.y]+0x0): undefined reference to `y';
example8.cpp:(.rdata$.refptr.x[.refptr.x]+0x0): undefined reference to `x';
F:\DEVC_workspace\collect2.exe [Error] ld returned 1 exit status