Results 1 to 7 of 7

Thread: [SDL] Creating a Smaller Executable

  1. #1
    Join Date
    May 2008
    Beans
    1,029

    Question [SDL] Creating a Smaller Executable

    I thought that I could make the output executable smaller by including sub-headers instead of the main "SDL.h", but the executable comes out to be the same size. Am I mistaken?

    PHP Code:
    #include <SDL/SDL.h> 
    vs.

    PHP Code:
    #include <SDL/SDL_video.h>
    #include <SDL/SDL_events.h> 
    Shouldn't the latter create a smaller executable?

  2. #2
    TenPlus1's Avatar
    TenPlus1 is offline Grande Half-n-Half Cinnamon Ubuntu
    Join Date
    May 2005
    Location
    Scotland, UK
    Beans
    836
    Distro
    Lubuntu

    Re: [SDL] Creating a Smaller Executable

    Wont the compiler only pull in what headers it needs/uses anyway, hence the same size executable ?

  3. #3
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: [SDL] Creating a Smaller Executable

    the number of headers have no impact on the size of the executable.
    they just contain information needed by the compiler to produce the executable from the source code (usually in .c/.cpp files)
    information provided by an header which is not needed does not flow into the final output.

    they only impact compilation time if you use an excessive amount of very large headers.

    to decrease executable size you can compile with -Os (which may make the program slower) and strip unneeded strings and debugging symbols from it with the strip command.

  4. #4
    Join Date
    May 2008
    Beans
    1,029

    Re: [SDL] Creating a Smaller Executable

    Okay, I thought that when "#include" was used it just added everything from the header files to the source code. I didn't realize that the compiler was smart enough to pull only what it needed.

  5. #5
    Join Date
    Nov 2007
    Location
    Canada
    Beans
    7
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SDL] Creating a Smaller Executable

    It's not that it "pulls what it needs". Header files are needed only during the compilation process (like MadCow108 said above) and they don't end up in the executable.

    Happy compiling!

  6. #6
    Join Date
    May 2008
    Beans
    1,029

    Re: [SDL] Creating a Smaller Executable

    Nvm

    I don't know how to delete a post.
    Last edited by dodle; March 3rd, 2011 at 05:54 AM.

  7. #7
    Join Date
    Mar 2011
    Location
    Raleigh, NC
    Beans
    8
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SDL] Creating a Smaller Executable

    as said above, it does affect compile time.

    basically it pulls every thing in, then the linker runs an optimizer that goes over and finds any 'dead' code thats not referenced by anything and removes it.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •