1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Object file of a programme

Discussion in 'Programming' started by capitus, Feb 25, 2013.

  1. #1
    Hey friends,

    I have some confusion about the object file of a computer program. When I write a program and compile it then 3 files are generated. Source file, execute file and object file. I have no confusion about source and execute file.

    What I write in a program is source file and execute file is the execution of that program. But what is the object file? What is its work in a program?



    If you know, please help me to know. Any help will be great for me.
     
    capitus, Feb 25, 2013 IP
  2. JamesLabonate

    JamesLabonate Member

    Messages:
    100
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    38
    #2
    An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)
    A linker takes all these object files and combines them to form one executable (assuming that it can, ie: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)
     
    JamesLabonate, Feb 27, 2013 IP
  3. vishals

    vishals Active Member

    Messages:
    208
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #3
    OP, what we call the process of compiling actually constitutes three stages and processes in a typical C compiler. The three stages or phases are

    i) pre processing
    ii) compiling
    iii linking

    in the first phase, a program called pre-processor is run on the source code. This program converts the pre-preocessor directives to their legitimate C code.

    In the second phase, the actual compiler is invoked, and that compiler converts the C code into object code. Object code is almost executable, but it requires to link against appropriate libraries. Lets say you used the printf function in your code. That printf function is defined in the libc library, so your program needs to link against that library.

    That linking step is done in third phase, when the linker is run. The linker will link all the different function calls, global extern variables, to their appropriate places.

    This three-step process is seen in all C compilers. And this is the reason why the full name of GCC is GNU's Compiler Collection, as seen here; http://en.wikipedia.org/wiki/GNU_Compiler_Collection. It is a collection of separate programs. In the Gnu's compiler collection, the pre-processor is a file named cpp, the C compiler is a program named cc, and the linker is a program named ld. The program named gcc is a front-end that runs all these other programs in the background. You can read more about it here:
    http://comsci.liu.edu/~murali/c/PreprocessCompileLink.htm.

    You can also easily google for other less verbose explanations by using the keywords "pre processor compiler linker" without the quotes.

    So to answer your question, an object file is produced by the actual c compiler, and it is much like the executable, but it does not yet know where to make the function calls ( it hasnt been linked). Therefore, you need to link it with the appropriate libraries to make it actually execute.

    I hope this helps!
     
    vishals, Mar 1, 2013 IP
  4. born_star16

    born_star16 Member

    Messages:
    297
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    36
    #4
    An object file is a output generated from compilation of a program. It is actually a machine code that has all the information required to execute the program exe.
     
    born_star16, Mar 6, 2013 IP
  5. Mohammad Asif Ali Zaman

    Mohammad Asif Ali Zaman Member

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #5

    As you know all ready that what is source file...as a source file is human readable code like that object file is machine readable code and is a output of compiler .....also contain function definition in the form of binary code(0,1) form..
    and used for build the project ,also used for combining of these files thanks