If you say g++ main.cpp
and this is your whole command line, the error is a linker error that it cannot find favNum
, right? In this case, try:
g++ main.cpp favourite.cpp
or compile compilation and binding:
g++ -c main.cpp -o main.o g++ -c favourite.cpp -o favourite.o g++ main.o favourite.o
Where -c
means: only compilation, no binding required and -o
filename
, because you want to write the output to two different object files in order to link them to the last command.
You can also add an additional flag, the most important of which are:
-Wall -Wextra -O3
source share