1

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.

Leonel
  • 55
  • 5
  • Normally, linkers *do* strip unused code from static libraries, and will strip code from your project with a couple choice flags. – Dietrich Epp Jan 16 '15 at 02:11
  • I would think it unlikely `D3DXCreateSphere` is a simple little function with no dependencies *of its own* in that library. – WhozCraig Jan 16 '15 at 02:12
  • There are thousands of 64 kilobytes demo out there that uses DirectX. check pouet.net. – v.oddou Jan 16 '15 at 02:17
  • Just FYI, `void main()` isn't valid C++. – cdhowie Jan 16 '15 at 02:23
  • @WhozCraig do you think it should be as much as 370Kb of instructions? It should be noted that using a lot more functionality of the same library also increments the same 370Kb. – Leonel Jan 16 '15 at 02:29
  • @v.oddou those 64Kb demos are not really portable, they require the "last directx runtime" (at the moment of release) installed. Newer versions of directx don't need d3dx, but I think they don't work with windows XP. – Leonel Jan 16 '15 at 02:45
  • That is probable indeed. But what I intended you to read between lines from my comment is that you can google blogs of the people who write these stuff and learn from that : https://fgiesen.wordpress.com/2011/01/24/x86-code-compression-in-kkrunchy/ – v.oddou Jan 16 '15 at 02:50
  • Never was a fan of ``#pragma (lib,...)``. Did you also try the "traditional" way to reference a library Visual Studio project settings -> Linker -> Additional libraries? Same result? – BitTickler Jan 16 '15 at 03:06
  • @user2225104 Yes, same results – Leonel Jan 16 '15 at 03:39
  • I would probably try to get some ideas about what is going on, using ``dumpbin /IMPORTS`` et. al. – BitTickler Jan 16 '15 at 13:59

1 Answers1

0

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.

nicebyte
  • 1,498
  • 11
  • 21
  • thanks for your answer, I already use those tools. I'm trying to strip unused parts of the library if it is possible someway. – Leonel Jan 16 '15 at 02:36
  • This doesn't really answer the question. The question is "why does linking to the library increase the size of my executable." This should be a comment on the question, not an answer. – cdhowie Jan 16 '15 at 02:39
  • It still provides a potential solution to the problem. Sorry for trying to be helpful. – nicebyte Jan 16 '15 at 02:54