Benefits of makefiles
Well, as you all know you can't compile multiple source files into one program with C++ (like in Java, for example, compile the main class and all necessary ones will too), so you need to find a way around that. One way is makefiles. I'm using Dev-C++, and another way I can do this is make a project in it, and include all the files in that, and select to rebuild all, which compiles it all and links it. I haven't found much problem with this, but it requires it all be in a project and I can't customize how it builds. Would it be wiser to build with makefiles? And also, these .o (object) files, what are they, and what are they used for?
o files are object files.
if your program consits of multiple source files, they first are all compiled individually.
what if one source file calls a function which is defined in another source file?
since the source files are compiled individually, the compiler can't resolve the function call.
thats what object files are for:
the compiler creates the code as far is this is possible, and places it into an object file.
also stored in an object file is a table with all symbols that were globally defined in the source file and another table (or is it the same table?) with all symbols that could not be resolved,
the linker takes the object files as input and starts resolving the symbols. so it checks which symbols could not be resolved and searches for object files which export these symbols, combines the object files and fills in the appropriate addresses.
so whenever you get an error like "unresolved reference error: could not find symbol foo" it is a LINKER error and not a COMPILER error.
using makefiles makes your program alot more portable. im using linux so there is no visual c and thus there are no projects.
most development environments support "export project as makefile" - but the output might range from quite good to extremly sucky.
anyway it can't be wrong learning how to write a makefile
when you compile *.java files you get *.class files. Them you can join them inside a zip, and rename it to *.jar.
in c++ you compile each *.cpp in a *.o or *.obj file, then the linker creates a final executable with all necessary symbols from the *.obj files.