C++ How to compile dll in a .exe

In order to achieve that you will need static linking. This requires that all your libraries (and the libraries they depend upon recursively) need to be available as static libraries. Be aware that the size of your executable will be large, as it will carry all the code from those static libraries. This is why shared libraries (DLLs) were invented in the first place, to be able to share common code among applications. However that does not always work so well on windows.

I think what you may really want is an installer that installs your executable and all it's dependent libraries.


There's an article in DDJ from 2002 that may have what you want:

  • Packing DLLs in your EXE by Thiadmer Riemersma

Basically it uses a combination of linking to the DLL using MSVC's 'delayed load' feature and packaging the DLL as an embedded resource in the EXE. The DLL is then automatically extracted at runtime when the first call to one of the exports is made.

I haven't used this technique so I can't really comment on how well it works, but it sure seems like a slick idea.


You can use ILMerge