compilation - Main C Program does not find header and methods -
wasn't sure how explain better in title. learning how separate code in c. have main, equivalent of arraylist class java (but converted c , basic) , header file declares struct , functions in use. using sample code out of text , using latest version of dev c++ windows 8.
every time try compile main get: in function main undefined reference "newlist" [error] id returned 1 exit status
here code:
main.c #include <stdio.h> #include "arraylist.h" int main(int numparms, char *parms[]){ list mylist; mylist = newlist(mylist); printf("end"); return 0; } arraylist.c #include <stdio.h> #include "arraylist.h" list newlist(list mylist){ mylist.size = 0; return mylist; } list add(list mylist, int value){ mylist.values[mylist.size] = value; mylist.size++; return mylist; } int get(list mylist, int position){ int entry; entry = mylist.values[position]; return entry; } int size(list mylist){ return mylist.size; } list delete(list mylist, int position){ int count; for(count =0; count<(mylist.size-1); count++){ mylist.values[count] = mylist.values[count+1]; } mylist.size --; return mylist; } void print(list mylist){ int count; printf("current list contents:\n"); if (mylist.size > 0){ (count=0; count<mylist.size; count++){ printf("element %d %d\n", count, get(mylist, count)); } printf("\n"); } else{ printf("the list empty\n\n"); } } arraylist.h #define max_size 100 typedef struct{ int size; int values[max_size]; }list; list newlist(list); list add(list, int); int get(list, int); int size(list); list delete(list, int); void print(list);
that linker problem. compilation ok, when linker tries assemble pieces can't find newlist anywhere. guess did not compile file arraylist.c , link result project.
Comments
Post a Comment