I am to compile a multi-file C++ program, and have the following error;
Undefined symbols for architecture i386:
"included::printMSG()", referenced from:
_main in ccQwMj1l.o
ld: symbol(s) not[Finished in 0.3s with exit code 1] found for architecture i386
collect2: ld returned 1 exit status
My code:
main.cpp: https://gist.github.com/3845822
included.cpp: https://gist.github.com/3845825
included.h: https://gist.github.com/3845827
(confirmed to work with g++)
EDIT: I am not putting these files in a project, they are just all in the same folder, and I’m compiling main.cpp
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 aMakefilethat has rules thatmakefollows`.A simple
Makefilecan look like this:There are other similar programs to handle this. One that is popular is CMake.