1

MSVC++ provides an optimization for programmers that want to deploy only a single executable file. You can build with /MT to link the C++ runtime library and the standard C++ library into the EXE; or /MD to call C++ runtime libraries (.DLL files).

But for your own code, or third party DLLs, is it possible to generate only a single executable file?

Suppose project PrjA uses PrjB; now, PrjB only generates dynamic library PrjB.dll, not static library PrjB.lib. It there a way to configure them so that PrjA could generate PrjA.exe, which embedded PrjB.dll inside, so that only 1 file need be deployed?

Note: the constraint iss that only PrjB.DLL is provided, no static library prjB.LIB. This question is different from C++ How to compile dll in a .exe .

MSVC /MD, /MT config using C++ Runtime Library:

  • /MD Causes the application to use the multithread-specific and DLL-specific version of the run-time library.

  • /MT Causes the application to use the multithread, static version of the run-time library.

Community
  • 1
  • 1
athos
  • 6,120
  • 5
  • 51
  • 95
  • *It there a way to configure them to acheive similar effect as /MD, /MDd, /MT, /MTd?* Please elaborate. It's not clear to me what you did not understand after reading the documentation for those flags. – R Sahu Nov 07 '16 at 05:08
  • Looks like question is "how to statically link all my projects into single executable". No idea what runtime library settings has to do with that, but to link your projects statically you need to change type of your projects from "dynamic library" to "static library". – Andrey Turkin Nov 07 '16 at 06:18
  • Well, make ProjB generate .lib then. /MD / /MT switches don't make .dll files go into .exe, they just select between 2 versions of the same library - one compiled as .dll and one compiled as .lib. If you really cannot make .lib and you really need single .exe then there are some tools that can "bundle" application into single exe post factum - see other question for more details. – Andrey Turkin Nov 07 '16 at 07:23
  • Possible duplicate of [C++ How to compile dll in a .exe](http://stackoverflow.com/questions/811720/c-how-to-compile-dll-in-a-exe) – Andrey Turkin Nov 07 '16 at 07:24
  • @AndreyTurkin I understand compiling prjB as `.LIB` is a solution, but am looking for a solution if only dynamic library `prjB.DLL` is available. – athos Nov 07 '16 at 07:27
  • Clearly you are **not** just generating a single executable file. Having the CRT linked into both files is excessively risky, the CRT has a lot of global state. It is not as drastically bad as it used to be, since VS2012 the CRT allocates from the process heap instead of creating its own heap, very hard to debug. But globals like *errno* and *locale* can still easily cost you a week of your life. You can get what you want, but PrjB needs to be a *static library* project so that it gets linked into the final EXE. Or its public interface needs to by hyper-pure, COM style. – Hans Passant Nov 07 '16 at 07:33
  • @HansPassant could you pls elaborate 1) "You can get what you want" -- how to get a single .EXE file to deploy? 2) what do you mean by "hyper-pure interface, COM style"? sorry I 'm not familar with COM. – athos Nov 07 '16 at 07:41
  • You are doing things you do not understand. *Don't do that* is the only easy to understand advice. It is pointless, you have to deploy 2 executable files anyway, there is no point whatsoever in avoiding deploying one more. – Hans Passant Nov 07 '16 at 07:47
  • @HansPassant I won't do it. It's more a thought experiment, to understand compiling and linking, to know more tech possible approaches. – athos Nov 07 '16 at 07:48

1 Answers1

0

As mentioned on several other SO answers, there are external tools available for this task. BoxedApp is highly regarded among them (but paid).

Community
  • 1
  • 1
Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101