Undefined reference to 'adjacency_array'

70 views Asked by At

When I try to compile my C program I get this error:

C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./objects/linked_list.o:linked_list.c:(.rdata$.refptr.adjacency_array[.refptr.adjacency_array]+0x0): undefined reference to `adjacency_array'
collect2.exe: error: ld returned 1 exit status

The adjacency_array is an extern Dynamic_Array * (the Dynamic_Array type is defined in data_types.h which is included in all of my source files) I declared in globals.h (which is included in all of my source files as well) and I define it in main.c. The error is thrown when I try to call a function in main.c that was defined in linked_list.c but I don't understand why the adjacency_array variable isn't seen in linked_list.c since it's included in there.

globals.h:

#pragma once

#include "data_types.h"

extern unsigned int id;
extern Dynamic_Array *adjacency_array;

main.c:

//...

Dynamic_Array *adjacency_array = new_dynamic_array();

// ...

I'm not sure what else I should include in my question, but I will provide more information if needed.

0

There are 0 answers