编译 Win32 应用程序,没有特定的依赖关系或大小膨胀

发布于 2024-10-19 04:52:08 字数 1204 浏览 7 评论 0 原文

我正在尝试使用 Visual C++ 2008 构建一个小型 Win32 应用程序,但我希望它可以在任何现代 Windows 计算机上运行,​​而不必提供额外的库,也不必扩大其静态链接的大小。

我在互联网上阅读了许多有关此主题的文章,例如 这个

我知道一个好主意是将我的项目动态链接到 msvcrt.dll,它可以在任何现代 Windows 中作为系统 dll 找到,而不是像 msvcr90 这样的较新的运行时,它随着每个新的 Visual Studio 版本而变化。

所以在链接器选项中, 我忽略了所有默认库(/NODEFAULTLIB) 我将 msvcrt.lib 添加到了附加依赖项中

,但是在编译时出现了一堆“无法解析的外部符号”错误,如下所示:

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)

我还尝试使用一些旨在减少大小膨胀的替代 C++ 运行时库,例如 Minicrt、WCRT 等,但是无论如何,我都会收到“无法解析的外部符号”错误。

非常感谢任何帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世态炎凉 2024-10-26 04:52:08

本例中的“膨胀”来自于 STL 的使用。因此,除非您想重构代码以摆脱 STL 引用,否则您可能会运气不好。

不过,我建议使用 WDK 构建应用程序。在 Windows XP 中,msvcrt.dll 被“授予”系统 DLL(即始终存在,无需再发行),据我所知,它也包含在 Windows 2000 SP4+SRP 中。因此,如果这些最低要求适合您,请使用 WDK 构建您的应用程序,所有“膨胀”都将位于 DLL 中,这些 DLL 应该已存在于任何受支持的系统上。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文