Hello everyone...
I've searched a lot for this but i can't really figure this out.
My project consists of 5 .c files and 4 .h headers. all in the same folder.
I compile them separately succesfully but when it comes to group compiling (gcc -o progname and all the code files in linux environment OR compile-all option in dev-c++) i have these errors in both occasions:
C:\Users\user\...\main.o(.text+0x9a) In function `main':
[Linker error] undefined reference to `dhmiourgia_Words'
[Linker error] undefined reference to `katastrofh_Words'
C:\Users\user\...\main.o(.text+0x1fb) In function `InitialiseTree':
[Linker error] undefined reference to `InsertWord'
....
and it goes on and on being unable to identify ALL the functions i use in main.c, define in Words.h and implement in Words.c
I first thought i missed the header #include pre-processor order but as you can see here it is!
How can i overcome these errors?
Below is the code files where the problem lies, All advice welcome, thanks again
/* file: main.c */
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h> /* for gettimeofday() */
#include "typos_stoixeiouDDA.h"
#include "Words.h"
void InitialiseTree(FILE *wordlist, typosWords W, int totalwordsin);
void SearchUpdateTree(FILE *wordlist, typosWords W);
void Results(typosWords W, int totalwordsin);
int main(void)
{ typosWords A;
FILE *FirstList, *SecondList;
char ap;
char ylop='B';
char arxeio[25];
int totalwordsin=0;
printf("Den exei dhmiourgithei ATD-Words\nDhmiourgia? (n/N gia epivevaiwsh)\n");
fflush(stdin);
ap=getchar();
if((ap=='n')||(ap=='N')){
do{
printf("Epilekste ylopoihsh dendrou (A gia AVL, B gia BST)\n");
fflush(stdin);
ylop=getchar();
if((ylop=='B')||(ylop=='A')){
A=dhmiourgia_Words();
printf("Dwse onoma arxeiou-listas leksewn pros anazithsh(ston idio ypofakelo!)\n");
scanf(" %s ", arxeio);
if((FirstList=fopen(arxeio, "r"))==NULL)
printf("Sfalma kata to anoigma tou arxeiou\n");
InitialiseTree(FirstList, A, totalwordsin);
fclose(FirstList);
printf("Arxeio pros eksetash: RomeoAndJuliet.txt\n");
if((SecondList=fopen("RomeAndJuliet.txt", "r"))==NULL)
printf("Sfalma kata to anoigma tou arxeiou\n");
SearchUpdateTree(SecondList, A);
fclose(SecondList);
Results(A, totalwordsin);
katastrofh_Words(&A);
}
else printf("Lathos apantisi\n");
}while((ylop!='A')&&(ylop!='B'));
}
printf("Eyxaristoyme poy mas protimhsate!\n");
return 0;
}
void InitialiseTree(FILE *wordlist, typosWords W, int totalwordsin)
{
int i=0, res;
char word[20];
struct timeval start, t0, t1, t2, t3, t4, t5, t6, tALL;
double elapsedTime;
gettimeofday(&start, NULL); /* start timer */
do{
res=fscanf(wordlist,"%s\n", word);
InsertWord(W, word);
i++;
if(i==1024*(2^0))
gettimeofday(&t0, NULL); /* save time */
if(i==1024*(2^1))
gettimeofday(&t1, NULL); /* save time */
if(i==1024*(2^2))
gettimeofday(&t2, NULL); /* save time */
if(i==1024*(2^3))
gettimeofday(&t3, NULL); /* save time */
if(i==1024*(2^4))
gettimeofday(&t4, NULL); /* save time */
if(i==1024*(2^5))
gettimeofday(&t5, NULL); /* save time */
if(i==1024*(2^6))
gettimeofday(&t6, NULL); /* save time */
}while(res!=EOF);
totalwordsin=i;
gettimeofday(&tALL, NULL); /* save total time */
/* calculating time for 1024*2^0 words to be inserted */
elapsedTime = (t0.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t0.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 0);
/* calculating time for 1024*2^1 words to be inserted */
elapsedTime = (t1.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t1.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 1);
/* calculating time for 1024*2^2 words to be inserted */
elapsedTime = (t2.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t2.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 2);
/* calculating time for 1024*2^3 words to be inserted */
elapsedTime = (t3.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t3.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 3);
/* calculating time for 1024*2^4 words to be inserted */
elapsedTime = (t4.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t4.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 4);
/* calculating time for 1024*2^5 words to be inserted */
elapsedTime = (t5.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t5.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 5);
/* calculating time for 1024*2^6 words to be inserted */
elapsedTime = (t6.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (t6.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 6);
/* calculating time for all words to be inserted */
elapsedTime = (tALL.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (tALL.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetInsertTime(W, elapsedTime, 7);
/* Reads words from wordlist(1)
inserts into DDA/AVL using InsertWord after 1024, 2048, 4096,... words
sets array times using SetInsertTime */
}
void SearchUpdateTree(FILE *wordlist, typosWords W)
{
struct timeval start, end;
double elapsedTime;
int res;
char word[20];
gettimeofday(&start, NULL); /* start timer */
do{
res=fscanf(wordlist,"%s\n", word);
CheckWord(W, word);
}while(res!=EOF);
gettimeofday(&end, NULL); /* stop timer */
elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetCheckTime(W, elapsedTime);
/* Reads words from wordlist(2)-RandJ
calls CheckWord
saves total Check time */
}
void Results(typosWords W, int totalwordsin)
{
struct timeval start, end;
double elapsedTime;
char ap;
int fileout;
char arxeio[25];
FILE* out;
do{
printf("Pathste O gia emfanisi apotelesmatwn sthn othoni\n");
printf(" F gia emfanisi apotelesmatwn se arxeio keimenou\n");
fflush(stdin);
ap=getchar();
if(ap=='O')
fileout=0;
else if(ap=='F'){
fileout=1;
printf("Dwse onoma arxeiou gia emfanisi apotelesmatwn (ston idio ypofakelo!)\n");
scanf(" %s ", arxeio);
if((out=fopen(arxeio, "w"))==NULL)
printf("Sfalma kata to anoigma tou arxeiou\n");
}
else
printf("Lathos apantisi\n");
}while((ap!='O')&&(ap!='F'));
gettimeofday(&start, NULL); /* start timer */
ShowCommonWords(out, W, fileout);
gettimeofday(&end, NULL); /* stop timer */
elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0; /* sec to ms */
elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0; /* us to ms */
SetDiadromhTime(W, elapsedTime);
fclose(out);
PrintTimes(out, W, fileout, totalwordsin);
}
/* file: Words.c */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "typos_stoixeiouDDA.h"
#include "Words.h"
#if ylop == 'B'
#include "BST_pointer-Recursive.h"
#elif ylop == 'A'
#include "AVL_pointer.h"
#endif
extern char ylop;
#if ylop == 'B' /* Ylopoihsh tou ATD-Words me aplo DDA(BST) */
typedef struct RecWords
{
typos_deikti WordsRiza; /* to Words apoteleitai apo to DDA */
float InsertTime [10]; /* xronoi eisagvghs ana 1024, 2048,... (7 sto synolo)
kai o xronos eisagogis OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float CheckTime; /* xronos anazhthshs OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float DiadromhTime; /* xronos diadromhs */
} RecWords;
typosWords dhmiourgia_Words()
{
typosWords WordsNew=malloc(sizeof(RecWords));
Tree_dimiourgia(&(WordsNew->WordsRiza));
return WordsNew;
}
void katastrofh_Words(typosWords * Wordsptr)
{
Tree_katastrofi(&(*Wordsptr)->WordsRiza);
free(*Wordsptr);
*Wordsptr=NULL;
}
void InsertWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
Tree_eisagogi(Words->WordsRiza, stoixeio, error);
if(*error) printf("Sfalma eisagogis stoixeioy sto dentro\n");
/*Input w
sets stoixeio DDA (kai ta 2 melh)
calls eisagogi_komvou sto DDA
*/
}
void CheckWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
int* found=0;
typos_deikti* deiktis;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
Tree_anazitisi(Words->WordsRiza, stoixeio, deiktis, found);
if(*found) deiktis->frequency++;
/* Input w
sets stoixeio DDA (kai ta 2 melh)
calls anazitisi_komvou and
??if found
calls periexomena and set???
*/
}
void ShowCommonWords(FILE *out, typosWords Words, int fileout)
{
Tree_endodiat(Words->WordsRiza, fileout, out);
/* diadromh DDA me parametro function for testing if In2nd==1 */
}
/* praxeis poy diaxeirizontai toys xronoys */
void SetInsertTime(typosWords Words, float time, int position)
{
Words.InsertTime[position]=time;
/* Input time, position
sets Words.InsertTime[position]=time;
*/
}
void SetDiadromhTime(typosWords Words, float time)
{
Words.DiadromhTime=time;
/* Input time
sets Words.DiadromhTime=time;
*/
}
void PrintTimes(FILE *out, typosWords Words, int fileout, int totalwordsin)
{
int i;
if(!fileout){
for(i=0; i<=6 ; i++){
printf("Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
printf("Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
printf("Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
printf("Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
else{
for(i=0; i<=6 ; i++){
fprintf(out, "Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
fprintf(out, "Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
fprintf(out, "Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
fprintf(out, "Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
/* emfanizei sthn othoni InsertTimes, DiadromhTime */
}
#elif ylop == 'A' /* Ylopoihsh tou ATD-Words me AVL-Tree */
typedef struct RecWords
{
typos_deikti WordsRiza; /* to Words apoteleitai apo to AVL */
float InsertTime [10]; /* xronoi eisagvghs ana 1024, 2048,... (7 sto synolo)
kai o xronos eisagogis OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float CheckTime; /* xronos anazhthshs OLWN twn leksevn
apo to epilegmeno arxeio eisodoy */
float DiadromhTime; /* xronos diadromhs */
} RecWords;
typosWords dhmiourgia_Words()
{
typosWords WordsNew=malloc(sizeof(RecWords));
AVLTree_dimiourgia(&(WordsNew->WordsRiza));
return WordsNew;
}
void katastrofh_Words(typosWords * Wordsptr)
{
AVLTree_katastrofi(&(*Wordsptr)->WordsRiza);
free(*Wordsptr);
*Wordsptr=NULL;
}
void InsertWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
AVLTree_eisagogi(Words->WordsRiza, stoixeio, error);
if(*error) printf("Sfalma eisagogis stoixeioy sto dentro\n");
/*Input w
sets stoixeio AVL (kai ta 2 melh)
calls eisagogi_komvou sto AVL
*/
}
void CheckWord(typosWords Words, char * w)
{
TStoixeioyTree stoixeio;
int* error=0;
int* found=0;
typos_deikti* deiktis;
strcpy(stoixeio.word, w);
stoixeio.frequency=0;
AVLTree_anazitisi(Words->WordsRiza, stoixeio, deiktis, found);
if(*found) deiktis->frequency++;
/* Input w
sets stoixeio AVL (kai ta 2 melh)
calls anazitisi_komvou and
??if found
calls periexomena and set???
*/
}
void ShowCommonWords(FILE *out, typosWords Words, int fileout)
{
AVLTree_endodiat(Words->WordsRiza, fileout, out);
/* diadromh DDA me parametro function for testing if In2nd==1 */
}
/* praxeis poy diaxeirizontai toys xronoys */
void SetInsertTime(typosWords Words, float time, int position)
{
Words.InsertTime[position]=time;
/* Input time, position
sets Words.InsertTime[position]=time;
*/
}
void SetDiadromhTime(typosWords Words, float time)
{
Words.DiadromhTime=time;
/* Input time
sets Words.DiadromhTime=time;
*/
}
void PrintTimes(FILE *out, typosWords Words, int fileout, int totalwordsin)
{
int i;
if(!fileout){
for(i=0; i<=6 ; i++){
printf("Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
printf("Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
printf("Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
printf("Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
else{
for(i=0; i<=6 ; i++){
fprintf(out, "Xronos eisagogis %d leksewn sto Words: %f\n", 1024*(2^i), Words->InsertTime[i]);
}
fprintf(out, "Xronos eisagogis OLWN twn leksewn sto Words: %f\n", Words->InsertTime[7]);
fprintf(out, "Xronos plhrous endodiatetagmenis diadromhs: %f\n", Words->DiadromiTime);
fprintf(out, "Mesos xronos diadromis ana leksi: %f\n", (Words->DiadromiTime)/totalwordsin);
}
/* emfanizei sthn othoni InsertTimes, DiadromhTime */
}
#endif
/* file: Words.h */
#ifndef __TYPOS_WORDS__
#define __TYPOS_WORDS__
#include <stdio.h>
/*orismos typou Words */
typedef struct RecWords * typosWords;
/* epikefalides praxewn */
/* praxeis poy yloioyntai me praxeis DDA */
typosWords dhmiourgia_Words();
void katastrofh_Words(typosWords * Wordsptr);
void InsertWord(typosWords Words, char * w);
void CheckWord(typosWords Words, char * w);
void ShowCommonWords(FILE *out, typosWords Words, int fileout);
/* praxeis poy diaxeirizontai toys xronoys */
void SetInsertTime(typosWords Words, float time, int position);
void SetCheckTime(typosWords Words, float time);
void SetDiadromhTime(typosWords Words, float time);
void PrintTimes(FILE *out, typosWords Words, int fileout, int totalwordsin);
#endif