0

Btree.h file

 #include "Type_Btree.h"
        extern Btree Create_Btree();
        extern int isEmpty_Btree(Btree B);
        extern Btree Construct(element e, Btree L, Btree R);
        extern int Root(Btree B, element *e);
        extern int Right(Btree B, Btree *R);
        extern int Left(Btree B, Btree *L);

the type file Type_Btree.h file

typedef int element;
typedef struct node{
    element data;
    struct node *left, *right;
}*Btree;

here are some functions concerning Binary trees Btree.c file

#include "Btree.h"
Btree Create_Btree(){
    return NULL;
}
int isEmpty_Btree(Btree B){
    return (B == NULL);
}
Btree Construct(element e, Btree L, Btree R){
    Btree temp;
    temp = (Btree) malloc(sizeof(struct node));
    if(!temp) return 0;
        temp -> data = 0;
    temp -> left = L;
    temp -> right = R;
    return temp;
}
int Root(Btree B, element *e){
    if(isEmpty_Btree(B)) return 0;
    *e = B->data;
    return 1;
}
int Right(Btree B, Btree *R){
    if(isEmpty_Btree(B)) return 0;
    *R = B->Right;
    return 1;
}
int Left(Btree B, Btree *L){
    if(isEmpty_Btree(B)) return 0;
    *L = B->Left;
    return 1;
}

here is the main file the main file

#include <stdio.h>
#include <stdlib.h>
#include "Btree.h"
int main()
{
   Btree a = Create_Btree();
    return 0;
}

this code is helping to implement the binary tree ,but when I try to run the code gives the error undefined reference to 'Create_Btree' it seems that the issue is with the link between the files

  • You declare "extern Btree Create_Btree();" in Btree.h but define "void Create_Btree()" in Btree.c. – Roxxorfreak Apr 18 '21 at 14:48
  • Show all compilation commands. Use the [GCC](http://gcc.gnu.org/) compiler as `gcc` with `-Wall -Wextra -g`, then use the [GDB](https://www.gnu.org/software/gdb/). See [this C reference](https://en.cppreference.com/w/c) and read the documentation of your compiler, your linker (e.g. [GNU binutils](https://www.gnu.org/software/binutils/)...), and of your debugger, then read some C standard like [n1570](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) or better – Basile Starynkevitch Apr 18 '21 at 14:50
  • no i wrote it wrong in the question that's why I edited it Roxxofreak – Adam Bazzal Apr 18 '21 at 14:51
  • Take inspiration from the source code of *existing* open source projects coded in C, such as [GNU coreutils](https://www.gnu.org/software/coreutils/) and [GNU make](https://www.gnu.org/software/make/) – Basile Starynkevitch Apr 18 '21 at 14:53
  • Your `Construct` function should return `NULL` (not `0`) on failure, and could use perhaps [perror(3)](https://man7.org/linux/man-pages/man3/perror.3.html) when it happens – Basile Starynkevitch Apr 18 '21 at 14:55

0 Answers0