构建 Visual C++不使用CRT函数的应用程序仍然引用一些

发布于 2024-08-08 16:28:09 字数 1075 浏览 2 评论 0原文

这是一系列至少两个密切相关但又截然不同的问题的一部分。我希望通过单独询问他们来做正确的事情。

我正在尝试让我的 Visual C++ 2008 应用程序在没有 C 运行时库的情况下运行。它是一个 Win32 GUI 应用程序,没有 MFC 或其他花哨的东西,只是简单的 Windows API。

所以我设置了项目属性->配置-> C/C++->高级->将默认库名称省略为“是”(编译器标志 /Zl)并重建。假设我已经编写了一个合适的入口点函数,这是我的另一个问题

我收到两个链接器错误;他们可能是相关的。链接器抱怨 foobar.obj 中未解析的外部符号 __fltused_memcpy。不用说,我在程序中没有显式地使用这两种方法,但我确实在 foobar.cpp 中的某处使用了 memcpy。 (我会使用 CopyMemory< /a> 但结果是 #defined 与 memcpy 相同...)

(我以为我可以摆脱 memcpy使用编译器内在函数(例如 #pragmatrinsic(memcpy))来解决问题,但这没有什么区别。)

如果我查看预处理器输出(将 /P 添加到编译器命令行),我在 foobar.i 中没有看到对 __fltused_memcpy 的引用。

所以,我的问题是:这些链接器错误从何而来,如何解决它们?

This is part of a series of at least two closely related, but distinct questions. I hope I'm doing the right thing by asking them separately.

I'm trying to get my Visual C++ 2008 app to work without the C Runtime Library. It's a Win32 GUI app without MFC or other fancy stuff, just plain Windows API.

So I set Project Properties -> Configuration -> C/C++ -> Advanced -> Omit Default Library Names to Yes (compiler flag /Zl) and rebuilt. Let's pretend I have written a suitable entry point function, which is the subject of my other question.

I get two linker errors; they are probably related. The linker complains about unresolved external symbols __fltused and _memcpy in foobar.obj. Needless to say, I use neither explicitly in my program, but I do use memcpy somewhere in foobar.cpp. (I would have used CopyMemory but that turns out to be #defined to be identical to memcpy...)

(I thought I could get rid of the memcpy problem by using a compiler intrinsic, like #pragma intrinsic(memcpy), but this makes no difference.)

If I look at the preprocessor output (adding /P to the compiler command line), I see no references to either __fltused or _memcpy in foobar.i.

So, my question is: Where do these linker errors come from, and how do I resolve them?

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

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

发布评论

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

评论(2

软糯酥胸 2024-08-15 16:28:09

__fltused 意味着您正在使用或至少声明了一些浮点数或双精度数。编译器注入这个“无用”符号来导致从 crt 加载浮动支持 .obj。您可以通过简单地声明一个名为

#ifdef __cplusplus
extern "C" {
#endif
int _fltused=0; // it should be a single underscore since the double one is the mangled name
#ifdef __cplusplus
}
#endif

WRT _memcpy 的符号来解决这个问题 - memcpy 是一个 __cdecl 函数,并且所有 cdecl 函数都会自动获得一个 _ 作为其装饰的一部分。所以,当你说“__cdecl memcpy”时 - 编译器&链接器去寻找一个名为“_memcpy”的符号。如果构建设置具有反对指示内在函数的调试设置,则仍然可以导入内在函数(即使是明确请求的)。因此,无论如何,您都需要在某个时候实现自己的 memcpy 和相关函数。

__fltused implies you are using or have at least declared some floats or doubles. The compiler injects this 'useless' symbol to cause a floating support .obj to get loaded from the crt. You can get around this by simply declaring a symbol with the name

#ifdef __cplusplus
extern "C" {
#endif
int _fltused=0; // it should be a single underscore since the double one is the mangled name
#ifdef __cplusplus
}
#endif

WRT _memcpy - memcpy is a __cdecl function, and all cdecl functions get an automatic _ as part of their decoration. so, when you say "__cdecl memcpy" - the compiler & linker go looking for a symbol called '_memcpy'. Intrinsic functions - even explicitly requested - can still be imported if the build settings have debug settings that contra-indicate intrinsics. So you are going to need to implement your own memcpy and related functions at some point anyway.

眼眸里的那抹悲凉 2024-08-15 16:28:09

我建议为 foobar.cpp 设置一次“生成程序集列表”(或类似的)编译器选项,然后检查汇编程序代码。这应该真正告诉您这些符号的用途。

I recommend setting the "generate assembly listing" (or some such) compiler option for foobar.cpp once, and then inspecting the assembler code. This should really tell you where these symbols are used.

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