I am to compile a multi-file C++ program, and have the following error;
Undefined symbols for architecture i386:
\"included::printMSG()\", referenced from:
You can't just compile a single file and hope all other files are automatically linked to it to create the final program.
One way to make that happen is to use a program called make, which reads a Makefile
that has rules that make
follows`.
A simple Makefile
can look like this:
CXXFLAGS = -Wall -g
my_pogram: main.o other_file.o third_file.o
g++ main.o other_file.o third_file.o -o my_program
main.o: main.cpp
g++ $(CXXFLAGS) -c -o main.o main.cpp
other_file.o: other_file.cpp
g++ $(CXXFLAGS) -c -o other_file.o other_file.cpp
third_file.o: third_file.cpp
g++ $(CXXFLAGS) -c -o third_file.o third_file.cpp
There are other similar programs to handle this. One that is popular is CMake.