Here is the source code for my qsort.c file. In main, I simply call my_qsort and print the resulting array.
#include "qsort.h"
int partition(int* arr, int left, int right)
{
int pivot = arr[right], i = left - 1, temp = 0;
for (int j = 0; j < right; j++)
{
if (arr[j] < pivot)
{
i++;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
temp = arr[i + 1];
arr[i + 1] = arr[right];
arr[right] = temp;
return i + 1;
}
void my_qsort_recursize(int *arr, int left, int right)
{
int partition_index = 0;
if (left > right)
{
partition_index = partition(arr, left, right);
my_qsort_recursive(arr, left, partition_index - 1);
my_qsort_recursive(arr, partition_index + 1, right);
}
}
void my_qsort(int *arr, int size)
{
my_qsort_recursive(arr, 0, size - 1);
}
when I run the command "gcc main.c qsort.c" I get the error:
/tmp/ccMikxiR.o: In function `my_qsort_recursize':
qsort.c:(.text+0x18b): undefined reference to `my_qsort_recursive'
qsort.c:(.text+0x1a2): undefined reference to `my_qsort_recursive'
/tmp/ccMikxiR.o: In function `my_qsort':
qsort.c:(.text+0x1cb): undefined reference to `my_qsort_recursive'
collect2: error: ld returned 1 exit status
I don't understand why it is saying this since I am specifying both main.c and qsort.c in the gcc commmand. Am I making a very silly mistake here? I have written many functions like this before and I have never had this problem before.