未解析的外部符号

发布于 2024-07-27 12:53:56 字数 726 浏览 4 评论 0原文

可能的重复:
什么是未定义引用/未解析的外部符号错误以及如何修复它?

我正在努力将大量 .h 和 .lib 文件从本机 C++ 包装到托管 C++,以便最终在 C# 中用作引用的 .dll。

我已经链接了 .lib 文件,到目前为止一切都很顺利。 在包装最新的 .h 文件时,当 2 个函数返回并出现链接错误时,我遇到了麻烦:

error LNK2019: unresolved external symbol __imp__htonl@4 referenced in function
"public: void __thiscall Field::setCharacter(unsigned char,int)"
(?setCharacter@Field@@QAEXEH@Z) myutils.lib 

我在链接器选项中引用了 myutils.lib ,因此这不应该是问题。

奇怪的是,我在这个特定的 .h 文件中有大约 20 个函数,除了 3 个函数之外,其余所有函数都链接得很好。

有任何想法吗?

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#.

I have the .lib files linked in and everything has been going smoothly so far. Upon wrapping the latest .h file, I hit a snag when 2 functions came back with the link error:

error LNK2019: unresolved external symbol __imp__htonl@4 referenced in function
"public: void __thiscall Field::setCharacter(unsigned char,int)"
(?setCharacter@Field@@QAEXEH@Z) myutils.lib 

I have referenced myutils.lib in the linker options, so that shouldn't be the issue.

What's strange is that I have about 20 functions in this particular .h file and all of the rest are linking just fine except for 3 functions.

Any ideas?

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

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

发布评论

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

评论(3

悲凉≈ 2024-08-03 12:53:56

缺少的符号是 __imp__htonl@4,它是 htonl 的 C++ 变形名称,htonl 是将长值从主机顺序转换为网络顺序的函数。 @4 用于修改输入参数,并且是 C++ 对重载函数支持的一部分,以允许链接器解析正确的函数而不会发生名称冲突。

确保您已链接到从中引用该符号的网络库。 大概你的包正在使用这个符号的一些特殊定义,而不是通常的宏。

The missing symbol is __imp__htonl@4, which is a C++ mangled name for htonl, which is a function that converts a long value from host to network order. The @4 is used to mangle the input parameters and is part of C++ support for overloaded functions to allow the linker to resolve the right function w/o name collisions.

Make sure that you are linked to the network library that you are referencing this symbol from. Presumably your package is using some special definition of this symbol, instead of the MACRO that it usually is.

烟火散人牵绊 2024-08-03 12:53:56

你确定签名匹配吗? 请务必检查符号性和常量性。 另外,请确保函数不是内联的。

Are you sure the signatures match? Be sure to checked for signed-ness and const-ness. Also, make sure functions aren't inlined.

雨后彩虹 2024-08-03 12:53:56

当我针对库进行编译然后在链接之前更改库时,我遇到了此错误。 确保您的标头与您的库提供的标头相同(不是从其他架构复制等)。 当然,请确保您链接到 ws2_32.lib(对于 mingw/gcc 为 -lws2_32)。

此外,如果您使用的是 GCC/mingw,您可能需要看一下: MinGW链接器错误:winsock

I ran into this error when I compiled against a library and then changed the library before linking. Make sure your headers are the same ones provided by your library (not copied from another architecture, etc). Of course, make sure you're linking against ws2_32.lib (-lws2_32 for mingw/gcc).

Additionally, if you are using GCC/mingw you may want to take a look at this: MinGW linker error: winsock

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