The Compiling Process

This is a discussion on The Compiling Process within the Tech Board forums, part of the Community Boards category; Please explain the stages of the compiling process. Can a function(not main) defined in one separate file be compiled into ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    Question The Compiling Process

    Please explain the stages of the compiling process.
    Can a function(not main) defined in one separate file be compiled into a exe or is it possible only to be compiled to a object file.
    During a Separate compiling process are the individual source files compiled all the way to be .exes or only to the stage of .objs and then linked using the linker to create the final application

    Can somebody tell me what are libraries in C++ and of what they consist of? Do they consist of separate compiled executable programs or object files
    Last edited by Varuna; 08-24-2007 at 11:45 AM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Can a function(not main) defined in one separate file be compiled into a exe or is it possible only to be compiled to a object file.
    a program needs an entry function. normally that's main. on win32 programs, its WinMain.
    During a Separate compiling process are the individual source files compiled all the way to be .exes or only to the stage of .objs and then linked using the linker to create the final application
    the second one.
    Can somebody tell me what are libraries in C++ and of what they consist of?
    they're basically specialized object files. an exe would have an entry function, shared libraries don't.

    note that there may be stub code that is run before the actual entry function in an exe.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The complete process of producing an executable file consists of:
    preprocessing (resolving #define macros, #inlude files and removing all comments [unless you specify not])
    compiling - translating the C/C++ code into machine code in an object file
    linking - combining one or more object files to a executable file.

    Whether you use separate compilation, or give mutliple input (.c/.cpp) files to the compiler doesn't change this.

    Libraries are essentially "a collection of object files" - it just makes a simple way to keep dozens or hundreds of object files in one place. The linker will select separate portions depending on what's needed - it also has some knowledge of "what else is needed from the library", so that if you call function A, which calls function B, the linker automatically includes function B too.

    The main difference between an object file and an executable file is that the executable file is "complete", whilst an object file may contain many "external references" that are not yet known - for example if your code calls printf(), it will pick up printf from a library when you link the application.

    --
    Mats

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    4
    Can you explain this a bit more please
    Libraries are essentially "a collection of object files" - it just makes a simple way to keep dozens or hundreds of object files in one place. The linker will select separate portions depending on what's needed - it also has some knowledge of "what else is needed from the library", so that if you call function A, which calls function B, the linker automatically includes function B too.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If we have a.obj, b.obj and c.obj in a lirbary, containing the object code generated by the compiler for functions A, B and C.

    A calls B.

    Your main calls A.

    The linker will look up A, and find out that it's in a.obj. It then finds that a.obj uses B and finds that it's in b.obj. So a.obj and b.obj are "dragged in" from the library as part of the linking process. C is not being used, so c.obj is NOT included in this executable.

    --
    Mats

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by robwhit View Post
    note that there may be stub code that is run before the actual entry function in an exe...
    ... which means that neither WinMain nor main is the actual executable entry point. So actually what you return from main or WinMain is fed into ExitProcess AND that is the last thing the executable ever does - Win32 ExitProcess function.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  4. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21