Defined a variable still getting an undefined reference error

45 Views Asked by At

x,y,z are 3 variables defined and declared in a function of radius_of_3_circles.c file. Once that function executes i.e. radius_x_y_z(); //line number 81 in code. The values of x,y,z get updated I want to use that in hit.c . I define x,y,z as extern in hit.c but still am getting an undefined reference error.

First I had a .h file but was getting a lot of linker errors and confusion.Therfore I brought all of the declarations in .c file only. Rest of the errors have gone but this keeps on coming. enter image description here

enter image description here

radius_of_3_circles.c

#include "stm32f4xx.h"
#include  <stdint.h>
void radius_x_y_z(void);

void radius_x_y_z(void)
{
int x;//extern
int y;//extern
int z;//extern
x=5;
y=3;
z=84;

}

hit.c

#include  <stdint.h>
#include "math.h"

void hit(void);

void hit(void)
{
     int a,s,X,Y,Z;
     int L=165;
     extern int x;//extern
     extern int y;//extern
     extern int z;//extern
     extern void radius_x_y_z(void);

     radius_x_y_z();
     s=x+y;

    if(s < L)
    {
        a = (L-s)/2 ; //inflate by a
        X = x + a;
        Y = y + a; //getting error here.
        Z = z + a;
    }

}

Not removing the pictures.Keeping them for reference and if someone wants to see the error msg.

0

There are 0 best solutions below