I am trying to call some information that I included in other files with ".h" extension to the main one. My problem is that when I try to call some function belonging to that file, I get the following error. Here is a part of the code to give you an idea of what happens to me. I already used switch, I already used include. But when I want to use the information from "heapsort.h" I get this:
menu.c:(text.+0xcc): undefined reference to heapSort
menu.c:(text.+0xcc): undefined reference to mergeSort
#include <stdio.h>
#include <stdbool.h>
#include "heapsort.h"
#include "mergesort.h"
void options()
{
int op = 30;
int n;
int array[5];
int i;
int cont;
int size;
while (op!=0)
{
printf("choose one buddy:\n")
printf("1. heap sort\n");
printf("2. merge sort.\n");
printf("0. exit\n");
scanf("%d", &op);
switch (op)
{
case 1:
printf("heap sort\n");
heapSort(array, n);
break;
case 2:
printf("merge sort\n");
mergeSort(array, n);
break;
case 0:
printf("byebye!");
break;
default:
printf("bad option dude\n");
break;
}
}
}
The error message
menu.c:(text.+0xcc): undefined reference to heapSort
menu.c:(text.+0xcc): undefined reference to mergeSort
is not a compiler error message, but a linker one. The meaning being that you have not included some object file (or the implementation of heapSort
nor mergeSort
, anywhere in the linking process)
As the comments to the question indicate, you should have provided a Minimal, complete and verifiable example which, lacking the contents of the include files you use, and the compilation units for the functions heapSort()
and mergeSort()
it is very difficult to assess you more in the subject.
To use an external library it's not only necessary to do proper #include <library.h>
in the source file, but you have to add compilation results of other units in the program. Normally, you have add the library properly installed in your system and use the linker option -l<libraryName>
where <libraryName>
is the name of the library to search for implementations of the functions you call in your code, or the already compiled objects of the compilation units where those functions are implemented. In spite you provide no information about the library you are using or the other modules of your program, no more help can be given to your question.