'Compile Win32 application without particular dependencies or size bloat

I am trying to build a small Win32 application using Visual C++ 2008, but I want it to run on any modern Windows machine without having to ship additional libraries and without having to bloat its size linking them statically.

I have read many articles around the internet about this topic, like this one.

I understood that a good idea would be to dynamically link my project to msvcrt.dll which can be found in any modern Windows being a system dll, on the contrary of newer runtimes like msvcr90 which change with each new Visual Studio version.

So in the linker options, I ignored all default libraries (/NODEFAULTLIB) I added msvcrt.lib to the additional dependencies

But I get a bunch of "unresolved external symbol" errors when compiling, like these ones:

1>StubLib.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast@std@@UAE@XZ)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast@std@@QAE@ABV01@@Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB)

I also tried to use some alternative C++ runtime libraries designed to reduce size bloat like Minicrt, WCRT etc. but in any case I get "unresolved external symbol" errors.

Any help is greatly appreciated.



Solution 1:[1]

The "bloat" in this case comes from the use of the STL. So unless you want to refactor your code to get rid of the STL references, you may simply be out of luck.

However, I can suggest using the WDK to build the application. With Windows XP the msvcrt.dll was "knighted" to a system DLL (i.e. always on board, no need for redistributables) and to my knowledge it was also included in Windows 2000 SP4+SRP. So if these minimum requirements are okay for you, use the WDK to build your application and all the "bloat" will be in DLLs that should be on any supported system already.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1