I keep getting this error when I try to compile three files at once:
gcc table.h table.c tabletest.c
tabletest.c:5: warning: return type defaults to âintâ
tabletest.c: In function âmainâ:
tabletest.c:10: warning: unused variable âpâ
/tmp/ccIOnFbt.o: In function `newTable':
/home/cc/cs61cl/fa09/class/cs61cl-bo/hw3/table.c:23: multiple definition of `newTable'
/tmp/ccwhxUwU.o:/home/cc/cs61cl/fa09/class/cs61cl-bo/hw3/table.c:23: first defined here
collect2: ld returned 1 exit status
table.h
table.cCode:struct table; struct table *newTable ( );
tabletest.cCode:#include <stdio.h> #include <stdlib.h> #include "table.h" struct table { int entrycount; }myTable; /* returns an empty table */ struct table * newTable ( ) { //struct table * table1 = malloc(sizeof(struct table)); myTable.entrycount = 0; return &myTable; }
Sorry if this is a really obvious error, but I have a pretty simple header set up, but why is it not compiling? Thanks in advance.Code:#include <stdio.h> #include <stdlib.h> #include "table.c" main() { struct table t; t.entrycount = 1; struct table *p = newTable(); printf("new address %d\n", p); return 0; }



LinkBack URL
About LinkBacks


