Thread: object files and linker

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    1

    object files and linker

    when I link files together, does the linker strip out unused code from the object file?

    For example, I create an object file that contains a lot of functions. I write a main.c that only calls one of the functions in the object code. Does the whole object file get included in my final exe?

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    1st source code:

    Code:
    file 1:
    
    #include <stdio.h>
    
    int main()
    {
            message1();
            return 0;
    }
    
    file 2:
    
    int message1()
    {
            printf("message");
            return 0;
    }
    2nd source code:
    Code:
    same first file
    
    file 2:
    
    int message1()
    {
            printf("message");
            return 0;
    }
    
    int message2()
    {
            printf("message");
            return 0;
    }
    Program 1 = 12.0kb without upx
    Program 2 = 12.1kb without upx

    :: I labled each source wrong, it's corrected. : :
    Last edited by Shadow; 04-26-2002 at 06:20 PM.
    The world is waiting. I must leave you now.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Ever more precise:

    Code:
    .              <DIR>        04-17-02  2:44a .
    ..             <DIR>        04-17-02  2:44a ..
    A        O           2,607  04-26-02  4:09p a.o
    A        C              80  04-26-02  4:07p a.c
    B        C             140  04-26-02  4:08p b.c
    C        C              69  04-26-02  4:08p c.c
    B        O           2,147  04-26-02  4:08p b.o
    C        O           1,933  04-26-02  4:09p c.o
    PGM      EXE        12,411  04-26-02  4:09p pgm.exe
    PGM2     EXE        12,383  04-26-02  4:09p pgm2.exe
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  2. Finding object code
    By kidburla in forum C Programming
    Replies: 3
    Last Post: 11-29-2005, 01:09 PM
  3. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  4. Makefiles, Object files, Source files, OH MY!
    By Inquirer in forum Linux Programming
    Replies: 2
    Last Post: 04-29-2003, 10:36 PM
  5. Compile with *.lib
    By Kelvin in forum C++ Programming
    Replies: 1
    Last Post: 07-23-2002, 06:24 PM