I would like to make a linked list globally available across multiple .c files.
I've read how to do this but I can't identify what is causing my problem.
I declare the variable with extern in LinkedList.h:
extern LinkedList* canQueue;
And then in main.c I initialise the variable by sending it to a function in LinkedList.c like so:
LinkedList *canQueue=createList();
This is the create function in LinkedList.c:
LinkedList* createList() /*creates empty linked list*/
{
LinkedList* myList;
myList = malloc(sizeof(LinkedList));
myList->head = NULL;
return myList;
}
I then want to use the canQueue in another file, cpu.c. I've included LinkedList.h in the cpu.c, so at this point the Linked List should be available here from what I know. But when I try to access it I get an error:
undefined reference to 'canQueue'
Have I missed something or done something wrong?