EDIT: IGNORE THIS. MODS PLEASE LOCK. PROBLEM SOLVED. READING IS POWER
Hello! Getting an undefined reference error. I've got two .c files at the moment.
pair is a struct with these contents:
char* word;
int last_index;
int list_size;
char** file_list;
this is its .c file:
the second file is a linked list. It utilizes nodes with the following structure:Code:#include "pair.h" #include <stdlib.h> #include <stdio.h> #include <string.h> Pair pair_construct(char* key, char* file) { Pair p = malloc(sizeof(struct pair)); p->word = key; p->file_list = calloc(1, sizeof(char*)); p->file_list[0] = file; p->last_index = 1; p->list_size = 1; } /* Purpose: free memory associated with a Pair * Input: A Pair * Output: Freed memory */ void free_pair(Pair p) { int i; for(i=0; i < p->list_size; i++) free(p->file_list[i]); free(p->word); free(p); } /* Purpose: Double the size of a pair's file list * to be used when the current list is full. * Input: A pair * Output: A pair with its file_list doubled in length */ void increase_file_list_length(Pair p) { p->list_size *= 2; p->file_list = realloc(p->file_list, p->list_size*sizeof(char*)); } /* Purpose: Add a file to a pair's file list * Input: A file name and pair * Output: The pair's file list updated */ void add_file(Pair p, char* file) { if(p->last_index == p->list_size) increase_file_list_length(p); p->file_list[p->last_index++] = file; }
Pair p;
Node next;
The function below spouts issues:
prev->p is a pair, and pair_free is a defined function taking a pair as its parameter, but for some reason I'm getting a compile error. Ive used pair functions in my test main in list.c with no problem, but this one is barking at me.Code:/* Purpose: Free memory associated with a list * Input: Head of a list * Output: Freed memory */ void list_free(Node head) { Node curr = head; Node prev = NULL; while( curr != NULL ) { prev = curr; curr = curr->next; pair_free(prev->p); //undefined reference error free(prev); } }
compiling with "gcc pair.c list.c" gives the following error:
/tmp/ccnS9s0p.o: In function `list_free':
list.c.text+0x137): undefined reference to `pair_free'
Any help is much appreciated



LinkBack URL
About LinkBacks
.text+0x137): undefined reference to `pair_free'


