Why does linking with Direct X increase my program size so much?

151 Views Asked by At

I need to make a program with the following requirements:

  • standalone (no installation)
  • optimized for size
  • windows XP compatible

The problem is that for example adding #include <d3dx9.h> and using a single function increments the executable size by 370kb.

Is there any way / tool so if I just use a couple of functions of a library, it is not entirely linked into the executable?

I tried the following with no success

  • release mode
  • whole program optimization
  • minimize size (/O1)
  • favor small code (/Os)
  • /OPT:REF
  • /OPT:ICF
  • use link time code generation (/LTCG)

This is the test code (I'm using a version of d3dx of October 2004 that allows static linking found here https://github.com/kavika13/jumpmanzero-thirdparty)

#pragma comment (lib, "d3dx9.lib")
#include <d3dx9.h>
int main() {
    D3DXCreateSphere(0, 0, 0, 0, 0, 0);
    return 0;
}

Notes: It should be noted that using a lot more functionality of the same library increments the same ~370Kb.

1

There are 1 best solutions below

3
nicebyte On

I was going to suggest /OPT:REF but then saw that you already tried that.

If all else fails you could try one of the "executable packer" options, such as ASPack (aspack.com) or UPX (upx.sourceforge.net).

They will compress you executable and won't introduce additional dependencies.