在没有 C 运行时的情况下使用 64 位整数 - 链接错误 __alldiv
我正在尝试在不使用 C 运行时(msvcrt 或 libcmt)的情况下构建 Windows 控制台应用程序。 也就是说,仅链接 kernel32.lib 并使用 WIN32 API 中的控制台函数而不是 printf 等。
我的问题是,在链接期间,编译器无法找到 __alldiv,它似乎可以处理 32 位应用程序中的 64 位整数除法。 我尝试了微软的编译器和英特尔的编译器。
该函数存在于运行时库中。 令人烦恼的是,像 64 位整数这样的基本数据将需要完整的 C 运行时。
有什么想法如何克服这个问题吗?
I am trying to build a windows console application without using the C runtime (msvcrt or libcmt). That is to link just against kernel32.lib and use console functions from WIN32 API instead of printf and such.
My problem is that during link the compiler fails to find __alldiv which seems to handle 64 bit integer divides in 32 bits applications. I tried both Microsoft's compiler and Intel's.
This function exist in the runtime libraries. It is quite annoying that something as basic as 64 bit integers will require the full C runtime.
Any ideas how to overcome the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
扩展精度除法例程可以处理比硬件除法器可以处理的除数更大的除数,这比您想象的要复杂。 我曾经不得不编写一个函数来将 128 位值除以 64 位值,这是相当痛苦的(并且在一般情况下很慢)。
看看 Randall Hyde 在他的 《Art of Assembly》中讨论的算法语言”文本(第 4 卷,第 4.2.5 节 - 扩展精度除法)。
这是摘录:
因此,您可能想做的一件事是确定是否确实需要在除数中使用 64 位数量 - 如果不需要,您可以轻松编写一个执行该任务的函数。 如果您确实需要将 64 位值除以 64 位值,您仍然可以这样做,但这是一个更困难的问题。 更具体地说,它可能不适合编译器“内联” - 因此它是一个库例程。
哦,不要忘记 - MS 提供了库源代码。
__alldiv()
是lldiv.asm
中的汇编语言函数。 将该文件添加到您的项目中并在没有库的其余部分的情况下链接它应该不会太难。An extended precision division routine that can deal with a divisor larger than the hardware divider can handle is more complex than you might think. I once had to write a function to divide 128 values by 64 bit values, and it was rather painful (and slow in the general case).
Take a look at the algorithm that Randall Hyde discusses in his "Art of Assembly Language" text (Volume 4, Section 4.2.5 - Extended Precision Division).
Here's an excerpt:
So, one thing you might want to do is determine if you really need to use 64-bit quantities in the divisor - if not, you can easily write up a function that will perform the task. If you really need to divide 64-bit values by 64-bit values, you can still do it, but it's a more difficult problem. More specifically it's probably not something that would be appropriate for a compiler to 'inline' - hence it's a library routine.
Oh, and don't forget - MS provides the library source code.
__alldiv()
is an assembly language function inlldiv.asm
. It shouldn't be too hard to just add that file to your project and have it linked in without the remainder of the library.找到了__alldiv链接问题的解决方案:
在msdev安装中找到lldiv.obj。
我可以将该目标文件而不是 C 运行时添加到链接中。
对我来说,路径是:
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\crt\src\intel\mt_lib\lldiv.obj。
Found a solution for the __alldiv link problem:
Found lldiv.obj in msdev installation.
I can add that object file to the link instead of the C runtime.
For me the path was:
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\crt\src\intel\mt_lib\lldiv.obj.
_alldiv 的 msdn 页面表示其用途是依赖于编译器优化设置,而不说明它依赖的设置是什么。
Wine 中还有一个 _alldiv 您可以借用。
The msdn page for _alldiv says its use is dependent on compiler optimisation settings, without saying what the settings it depends on are.
There's also an _alldiv in Wine you might be able to borrow.