Riccardo 'Taro'
New Coder
Hi there! I got a strange error when i was trying to create a library with a function that execute a bubble-sort. The error is this:
" undefined reference to `bubblesort'
collect2.exe: error: ld returned 1 exit status "
I leave the codes of the .h .c and main.c files below.
I think i'm one of the few who got this error-code. If someone here can help me i would be really glad. Thanks!
" undefined reference to `bubblesort'
collect2.exe: error: ld returned 1 exit status "
I leave the codes of the .h .c and main.c files below.
I think i'm one of the few who got this error-code. If someone here can help me i would be really glad. Thanks!
C:
extern void bubblesort (int, int[]);
C:
#include "bbsort.h"
void bubblesort (int n, int a[]) {
int i, j, temp;
for (i=0; i<n-1; i++)
for (j=0; j<n-1; j++)
if (a[j]>a[j+1]) {
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
C:
#include "bbsort.h"
#include <stdio.h>
#define n 8
int main () {
int a[n];
printf ("insert values in the arrey:\n\t"); //load the arrey
for (int i=0; i<n; i++) {
scanf("%d", &a[i]);
printf ("\t");
}
bubblesort(n, a); //bubblesort instruction
for (int i=0; i<n; i++) { //print the sorted arrey
printf ("%d\t", a[i]);
}
return 0;
}