Thread: Benefits of makefiles

  1. #1
    Join Date
    Jun 2005

    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?

  2. #2
    Registered User
    Join Date
    Aug 2001
    o files are object files.

    if your program consits of multiple source files, they first are all compiled individually.
    the problem:
    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
    signature under construction

  3. #3
    Registered User
    Join Date
    Jun 2004
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefiles
    By TriKri in forum Windows Programming
    Replies: 3
    Last Post: 03-30-2008, 06:57 AM
  2. benefits of private or protected constructor
    By George2 in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2007, 01:02 AM
  3. Benefits of learning assembly language?
    By 747ken in forum A Brief History of
    Replies: 5
    Last Post: 11-02-2003, 07:16 PM
  4. programming linux with gcc, emacs, and makefiles
    By Captain Penguin in forum Linux Programming
    Replies: 1
    Last Post: 11-02-2002, 12:04 PM
  5. Help with Makefiles
    By WebmasterMattD in forum Linux Programming
    Replies: 3
    Last Post: 05-24-2002, 08:51 AM