How to properly include other .cpp files into my main .cpp?

1 week ago 9
ARTICLE AD BOX

I have this part of my code where I have an array and want to compare it with other constant arrays, to find a match. As I am working with Multi-dimensional arrays, I decided to store these constants in another .cpp file, but I am getting the following error when trying to compile:

undefined reference to `charMaps'

collect2.exe: error: ld returned 1 exit status

My code is the following:

charMaps.cpp

#include "header.h" const bool charMaps[12][7][5] = {/*A lot of 0s and 1s*/}

header.h

#ifndef HEADER_H #define HEADER_H extern const bool charMaps[12][7][5]; #endif

main.cpp

#include "header.h" int main() { cout << getChars(); } int getChars { for (int k = 0; k < 12; k++) { for (int j = 0; j < 7; j++) { for (int i = 0; i < 5; i++) { if (pixelMap[j][i] != charMaps[k][j][i]) { goto continue2; } } } arraysEqual = 1; continue2:; if (arraysEqual) { return k; } } cout << "FAIL TO IDENTIFY THE NUMBER\n"; return 0; }

As additional notes, I am working with MinGW compiler, and VSCode, if it matters in some way.

Read Entire Article