Thread: Regarding C Linkage

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Regarding C Linkage

    Hi,
    I have a query. If there is a C program with one source file containing:
    int main()
    {
    return 0;
    }

    and no included headers and no libraries linked to it. Then why it is necessary to do linking to get an executable code. As per my knowledge a linker only links the different complied units. But in this case there is only one compiled file.
    Anybody plz explain this to me.

    Regards,
    Archana

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    I think the standard c library is always included.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Std Lib

    But here i didn't included std library explicitly. Or u mean std lib is implicitly included in every C program.

  4. #4
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    Everything is linked together by addresses. When your program is compiled, the Linker is required to resolve all symbol and label references, as well as build a jump-table and resolve all your relative addresses.

    If for some reason, you reference something that is in another library, it will load that library to resolve the address for that reference. But even if you don't, you still require the Linker to handle your own references.

    You can't compile without a linker.
    It is not the spoon that bends, it is you who bends around the spoon.

  5. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680

    Re: Std Lib

    Originally posted by Archana
    But here i didn't included std library explicitly. Or u mean std lib is implicitly included in every C program.
    Did you ever needed to include a library for the functions printf, fopen or fgets? No, that's because the're all included in the standard C library and this library is ALWAYS linked with your code.

    Cheers,
    Monster

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linkage question
    By DL1 in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2009, 07:56 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM