I'm trying to use an extern file pointer declared in a header file in two different .cpp files. The following code is a reduced version of my project, but the logic is the same:
file2.h:
extern FILE* output;
void print_stuff();
file1.cpp:
#include "file2.h"
int main() {
output = fopen("hello.txt", "w");
print_stuff();
}
file2.cpp
void print_stuff() {
fprintf(output, "hello\n");
}
however, I'm getting undefined reference errors to the output filepointer in both cpp files. Is there something I'm doing wrong?