Problems in creating libraries

Joined
Nov 3, 2024
Messages
1
Reaction score
0
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!

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,032
Latest member
OdellBerg4

Latest Threads

Top