Elad Cohen Elad Cohen - 10 months ago 56
Linux Question

How can I compile my CPP project on debian?

I just moved my project from my PC into a virtual machine running Debian.
My project contains some classes and headers, how can I compile it with G++?

ls -l
-rw-r--r-- 1 root root 2369 Nov 27 20:17 Card.cpp
-rw-r--r-- 1 root root 1299 Nov 27 15:56 Deck.cpp
-rw-r--r-- 1 root root 6529 Nov 27 20:58 Game.cpp
-rw-r--r-- 1 root root 4639 Nov 27 20:12 Hand.cpp
drwxr-xr-x 2 root root 4096 Nov 27 20:00 inc
-rw-r--r-- 1 root root 19 Nov 18 10:35 main.cpp
-rw-r--r-- 1 root root 5113 Nov 27 20:05 Player.cpp
drwxr-xr-x 2 root root 4096 Nov 28 07:58 src

/src ls -l
-rw-r--r-- 1 root root 490 Nov 28 07:58 reviiyot.cpp (this is the main)

/inc ls -l
-rw-r--r-- 1 root root 1506 Nov 26 17:31 Card.h
-rw-r--r-- 1 root root 842 Nov 25 12:25 Deck.h
-rw-r--r-- 1 root root 830 Nov 26 23:55 Game.h
-rw-r--r-- 1 root root 774 Nov 27 15:55 Hand.h
-rw-r--r-- 1 root root 2383 Nov 27 20:00 Player.h

Answer Source

You need to specify both all your .cpp files as well as the path to the include directory, so in your case the compile command could look something like

g++ src/reviiyot.cpp -I inc/ ./*.cpp -o executableFile

Note: it would be more natural to place the implementation files of your headers (the .cpp files, except your main) inside the src/ directory and leave the main.cpp inside the main directory