I am new to programming in C and I am currently trying test to see if my linked list working correctly but I keep running in to the following error whenever I use my Makefile:
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to \`WinMain'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:2: NodeStruct] Error 1
I made sure to save all my files and to have a main function included.
All files I am working with:
NodeStruct.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "linked_list_utils.h"
int main(int argc, char *argv[]){
Node* root = NULL;
insert_end(&root, "hello");
for(Node* curr = root; curr !=NULL; curr = curr->next){
printf("%s\n", curr->x);
}
deallocate(&root);
return 0;
}
linked_list_utils.h
#ifndef LIST_H
#define LIST_H
typedef struct Node{
char *x;
struct Node* next;
}Node;
void insert_end(Node **root, char x[]);
void deallocate(Node** root);
#endif
linked_list_utils.c
#include <stdio.h>
#include <stdlib.h>
#include "linked_list_utils.h"
void insert_end(Node **root, char x[]){
Node * newNode = malloc(sizeof(Node));
if(newNode == NULL){
exit(1);
}
newNode->next = NULL;
newNode->x = x;
if(*root == NULL){
*root = newNode;
return;
}
Node* curr = *root;
while(curr->next != NULL){
curr = curr->next;
}
curr->next = newNode;
}
void deallocate(Node** root){
Node* curr = *root;
while(curr != NULL){
Node* aux = curr;
curr = curr->next;
free(aux);
}
*root = NULL;
}
Makefile
NodeStruct: NodeStruct.o linked_list_utils.o
gcc -o NodeStruct.o linked_list_utils.o
NodeStruct.o: NodeStruct.c linked_list_utils.h
gcc -c NodeStruct.c
linked_list_utils.o: linked_list_utils.c linked_list_utils.h
gcc -c linked_list_utils.c
clean:
rm -f *.o *.exe