Hey there,
I've been working on a small Terminal-Snake Program to better understand C++.
This project was started off with just a crude outline of what it would become and after a while I realised that it needed more structure so I went ahead and divided the code into a few different files while trying to keep it as clean as possible.
At this point I started getting these compilation errors where the linker apparently fails to link some stuff (This is how it's looking like currently, but the errors were all pretty similar):
make -k
rm TSnake.x || true
g++ Consumables.cpp Snake.cpp TSnake.cpp -o TSnake.x -l ncurses -g
/sbin/ld: /tmp/ccUig2o6.o: in function `mangeInput()':
/home/maus/Cxx/TSnake/TSnake.cpp:92: undefined reference to `useConsumable(int, int)'
/sbin/ld: /tmp/ccUig2o6.o: in function `main':
/home/maus/Cxx/TSnake/TSnake.cpp:120: undefined reference to `insertConsumable(ConsumableType, int, int, int, int)'
/sbin/ld: /home/maus/Cxx/TSnake/TSnake.cpp:122: undefined reference to `tickGameObjects()'
/sbin/ld: /home/maus/Cxx/TSnake/TSnake.cpp:128: undefined reference to `insertConsumable(ConsumableType, int, int, int, int)'
/sbin/ld: /home/maus/Cxx/TSnake/TSnake.cpp:133: undefined reference to `insertConsumable(ConsumableType, int, int, int, int)'
collect2: error: ld returned 1 exit status
make: *** [makefile:9: all] Error 1
I figured that this might be related to circular dependencies so I changed my project structure to this:
Consumables.cpp < Consumables.h > TSnake.cpp
Snake.cpp < Snake.h > TSnake.cpp
This sadly turned out to be unsuccessful so my best guess is that this is related to my g++ flags. I tried searching for problems like this on the web, but including Consumables.cpp and Snake.cpp into the list of to-compile files is all that is being suggested on the web.
I have no clue what else I could do so I decided to seek help in this very 90s but adequate forum ;)
This is the repository of my code, if anyone is interested:
https://gitlab.com/UltraBlackLinux/tsnake
Thanks!
(--I sure hope that the formatting worked out as I intended. The Preview button does not appear to be showing anything apart from a box with my Username.-- Formatting did not work.)