“math.h”中的 _HUGE 和 __IMP__HUGE

发布于 2024-12-14 04:49:12 字数 510 浏览 0 评论 0原文

我有一个关于 math.h 中定义的常量如何链接的问题。

在 Visual Studio 2010 中,我正在使用“MD”构建一个 64 位 dll C++ 库,该库使用使用“HUGE_VAL”的第三方库。从标题“math.h”来看,“HUGE_VAL”似乎被定义为“_HUGE”。当我尝试构建时,链接错误导致

错误 LNK2001: 无法解析的外部符号 _HUGE

经过一些谷歌搜索后,我认为 _HUGE 应该在 msvcrt.lib 中定义。 MSVCRT.lib已链接,但我没有链接libcmt.lib,因为它会导致重新定义错误。

让我感到奇怪的是,当我创建一个使用 HUGE_VAL 并使用 /verbose 作为链接器选项的简单控制台程序时,它显示 _IMP_HUGE 正在链接。

我真正好奇的是_HUGE在什么阶段变成_IMP_HUGE?另外,是否还有其他人遇到了未解决的 _HUGE 错误?是否有人对如何修复它有任何想法?

感谢您阅读这个长问题并提出任何想法。

I have a question about how constants defined in math.h are linked.

In visual studio 2010, I'm building a 64-bit dll c++ library with "MD" that uses a third party library that make use of "HUGE_VAL". From the header "math.h", it seems that "HUGE_VAL" is defined as "_HUGE". When I try to build, a linking error results

error LNK2001: unresolved external symbol _HUGE

After doing some googling, I think _HUGE should be defined in msvcrt.lib. MSVCRT.lib is linked, but I didn't link libcmt.lib because it would cause re-definition errors.

What strikes me as odd is that when I create a simple console program that uses HUGE_VAL and use /verbose as a linker option, it shows _IMP_HUGE being linked.

What I'm really curious of is at what stage does _HUGE turn into _IMP_HUGE? Also, have anyone else gotten the unresolved _HUGE error and does anyone have any ideas for how it could be fixed?

Thanks for reading the long question and for any ideas.

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

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

发布评论

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

评论(1

稳稳的幸福 2024-12-21 04:49:12

我在VC11.0中遇到过这个问题。我得到的唯一错误是未解析的符号 _HUGE 错误。

我正在链接动态多线程运行时库,我发现如果我在链接步骤中包含“libcmt.lib”,那么问题就可以解决(或解决)。

我开始研究如何在 SDK 中定义标头来寻找线索,发现我在编译步骤中缺少编译器预目录:_DLL。

当您使用动态运行时库进行构建时,_HUGE 变量需要是 __declspec(dllimport),以便可以找到它。当您包含“math.h”时 ->如果没有将 _DLL 设置为预指令,则“crtdefs.h”变量将不会被 __declspec(dllimport) 编辑,并且会在链接时显示缺失。

我遇到这个问题是因为我正在使用自己的自定义 makefile 进行编译,并且忽略了添加 _DLL 预指令。将 -D_DLL 添加到我的编译步骤解决了编译问题,无需其他更改。

我知道这个线程很旧,但我想我会把它扔在那里,因为它可能会帮助有类似问题的人。

I have experienced this issue with VC11.0. The only error I get is an unresolved symbol _HUGE error.

I am linking with dynamic multi-threaded run time libraries and I found that if I were to include "libcmt.lib" in my link step, then the issue is resolved (or worked around).

I started looking into how the headers were defined in the SDK for clues and found that I was missing a compiler pre-directory in my compile steps: _DLL.

When you build with dynamic run time libraries the _HUGE variable needs to be __declspec(dllimport) so it can be found. When you include "math.h" -> "crtdefs.h" without setting _DLL as a pre-directive, the variable will not be __declspec(dllimport)'ed and will appear missing at link time.

I was getting this issue because I am compiling with my own custom makefiles and I had neglected to add the _DLL pre-directive. Adding -D_DLL to my compilation step resolved the compile issue with no other changes needed.

I know this thread is old, but figured I would throw it out there as it may help someone with a similar issue.

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