Here is my code:
#include <stdio.h>
#include <stdlib.h>
int compare(int a, int b);
main()
{
int x,y;
x = 2, y = 1;
printf("%d", compare(x,y));
int compare(int a, int b)
{
int returnValue = 0;
if(a>b)
returnValue = 1;
else if(a<b)
returnValue = -1;
else
returnValue = 0;
return(returnValue);
}
}
And this is the compiler error that I recieve:
In function `main':
asdf.c:(.text+0x21): undefined reference to `compare'
collect2: error: ld returned 1 exit status
I have looked into this problem, and every question that I can find with this error is because people are importing functions from different files. These two functions are in the same file, and the compare()
function is declared before the main()
. I would appreciate any help as to why I am getting this error.
Thank you for your time.