"undefined reference to" in G++ Cpp
Solution 1:
g++ main.cpp Help.cpp
You have to tell the compiler all the files that you want it to compile, not just the first one.
Solution 2:
You should add help.o to your g++ line:
g++ -c help.cpp -o help.o
g++ help.o main.cpp
By splitting it to two lines you can save compilation time (in case of larger projects), because you can compile help.cpp
only when it was changed. make
and Makefile
used well will save you a lot of headache:
#Makefile
all: main
main: help main.cpp
g++ -o main help.o main.cpp
help: help.cpp
g++ -c -o help.o help.cpp