2

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.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
Viotto01
  • 31
  • 1
  • 3

1 Answers1

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.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
  • Thanks for your anwer, but what do you mean by using Windows Driver Kit to build my application? I've already tried to use the different msvcrt.lib provided in WDK but I get same kind of errors. – Viotto01 Feb 28 '11 at 11:00
  • @Viotto01 These errors are *linker* errors, so the missing symbols need to be supplied by you or by a library. Both your subject and the question didn't make it clear that your main objective is to get rid of the _linker_ errors, but that you wanted to cut down on dependencies and "bloat". So the right thing here is to address the dependencies, which I addressed in the first paragraph. The other option is to rely on DLLs to save on the binary size. – 0xC0000022L Mar 07 '23 at 09:20