user2286858 user2286858 -4 years ago 166
C Question

Compile error with max_min.c:(.text+0x3c): undefined reference to `max_func'

I created simple max and min func to show max value and min value from user inputs but I got below error. could you please give me any help?

include



void max_func(int i, int j);
void min_func(int i, int j);

void main(void)
{

int i,j;
scanf("%d %d",&i,&j);

max_func(i,j);
min_func(i,j);

void max_func(int i,int j){
if ( i>j )
printf("Max Value is %d", i);
else
printf("Max Value is %d", j);
}

void min_func(int i,int j){
if ( i<j )
printf("Min Value is %d", i);
else
printf("Min Value is %d", j);
}


}

ubuntu:~$ gcc max_min.c -o max.out
/tmp/ccxQ242Y.o: In function
main':
max_min.c:(.text+0x3c): undefined reference to
max_func'
max_min.c:(.text+0x4b): undefined reference to `min_func'
collect2: error: ld returned 1 exit status

Answer Source

max_func() and min_func() are not supposed to be inside main(void){ ... }

The definitions i.e.:

void max_func(int i,int j){
    if ( i>j )
        printf("Max Value is %d", i);
    else
        printf("Max Value is %d", j);
}

(and similar for max_func) should be after the closing } of main().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download