构建 Visual C++不使用CRT函数的应用程序仍然引用一些
这是一系列至少两个密切相关但又截然不同的问题的一部分。我希望通过单独询问他们来做正确的事情。
我正在尝试让我的 Visual C++ 2008 应用程序在没有 C 运行时库的情况下运行。它是一个 Win32 GUI 应用程序,没有 MFC 或其他花哨的东西,只是简单的 Windows API。
所以我设置了项目属性->配置-> C/C++->高级->将默认库名称省略为“是”(编译器标志 /Zl
)并重建。假设我已经编写了一个合适的入口点函数,这是我的另一个问题
我收到两个链接器错误;他们可能是相关的。链接器抱怨 foobar.obj
中未解析的外部符号 __fltused
和 _memcpy
。不用说,我在程序中没有显式地使用这两种方法,但我确实在 foobar.cpp
中的某处使用了 memcpy
。 (我会使用 CopyMemory
< /a> 但结果是 #define
d 与 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 #define
d 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
__fltused
意味着您正在使用或至少声明了一些浮点数或双精度数。编译器注入这个“无用”符号来导致从 crt 加载浮动支持 .obj。您可以通过简单地声明一个名为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 nameWRT _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.
我建议为 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.