简体   繁体   English

尽管没有外部库,但未解决的外部问题

[英]Unresolved externals despite no external library

I have a very simple C++ test project that is giving me the error:我有一个非常简单的 C++ 测试项目,它给了我错误:

   error LNK2001: unresolved external symbol "int __cdecl DnsPluginInitialize(void *,void *)" (?DnsPluginInitialize@@YAHPEAX0@Z)

My header file is like so:我的头文件是这样的:

#ifdef DNSPLUGIN_EXPORTS
#define DNSPLUGIN_API __declspec(dllexport)
#else
#define DNSPLUGIN_API __declspec(dllimport)
#endif

DNSPLUGIN_API int DnsPluginInitialize(PVOID, PVOID);

and my cpp file is just this:我的cpp文件就是这样的:

#include "stdafx.h"
#include "DnsPlugin.h"


#pragma comment(linker,"/EXPORT:DnsPluginInitialize=?DnsPluginInitialize@@YAHPEAX0@Z")
DNSPLUGIN_API int DnsPluginInitialize(PVOID a1, PVOID a2) { 
    return 0; 
}

I'm very new to C++ and spent a lot of time trying to figure this out myself but just can't get there, as everything online seems to suggest I'm missing an external library... but I'm not using any.我对 C++ 很陌生,花了很多时间试图自己解决这个问题,但就是无法到达那里,因为网上的一切似乎都表明我缺少一个外部库......但我没有使用任何.

Further info in case it helps:如果有帮助,请提供更多信息:

This is a win32 DLL project in Visual Studio 2010.这是 Visual Studio 2010 中的 win32 DLL 项目。

The DnsPluginInitialize function needs to be called by an external program and apparently this export signature is correct (I have seen other people using this exact code in their examples) DnsPluginInitialize 函数需要由外部程序调用,显然这个导出签名是正确的(我已经看到其他人在他们的示例中使用了这个确切的代码)

So it seems like its an issue with x86 vs x64 differences... which is not something I would have guessed from the error message.因此,这似乎是 x86 与 x64 差异的一个问题……这不是我从错误消息中猜到的。

If I change the project to target the x64 platform, it compiles straight away with no errors.如果我将项目更改为面向 x64 平台,它会立即编译而不会出错。 But as soon as I change back to Win32, I get that same error about unresolved external symbols.但是,一旦我改回 Win32,就会遇到有关未解析的外部符号的相同错误。

However, I can get it to compile for Win32 if I just remove the pragma comment export and let __declspec(dllexport) take care of the export.但是,如果我只是删除 pragma 注释导出并让__declspec(dllexport)处理导出,我可以让它为 Win32 编译。 I still end up with DnsPluginInitialize@@YAHPEAX0@Z as the export signature when I look at the file with DumpBin but I guess I can just use extern "C" to avoid that for the 32 bit version.当我使用 DumpBin 查看文件时,我仍然以DnsPluginInitialize@@YAHPEAX0@Z作为导出签名,但我想我可以使用extern "C"来避免 32 位版本的这种情况。 EDIT: Actually can't I just use extern C for both the 32 bit and 64 bit versions?编辑:实际上我不能在 32 位和 64 位版本中都使用extern C吗? It seems like all the pragma comment export is trying to do is make it so calling the function name on its own will work without having to use the decorated name right?似乎所有 pragma 注释导出试图做的就是让它自己调用函数名,而不必使用修饰名,对吗?

So for now I'm happy it works, but I'm still pretty curious what causes this.所以现在我很高兴它有效,但我仍然很好奇是什么原因造成的。 I'm guessing its something to do with __cdecl being ignored on X64 combined with pragma comment /export not being supported for __cdecl .我猜这与__cdecl在 X64 上忽略以及__cdecl 不支持pragma comment /export 有关系 But I don't know enough about C++ yet to really know what's going on.但是我对 C++ 的了解还不够,还不能真正知道发生了什么。 If anyone wants to propose their explanations, I'd be keen to hear them.如果有人想提出他们的解释,我很想听听他们的意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未解决的外部,未解决的外部符号LNK 1120 - Unresolved Externals, Unresolved external symbol LNK 1120 动态数学库 - 未解析的外部 - Dynamic math library - unresolved externals 尽管在 zlib.lib 中链接,但未解决的外部问题 - Unresolved externals despite linking in zlib.lib 解决未解析的外部符号CSourceSeeking :: CSourceSeeking(...)尽管链接到正确的库 - Resolving unresolved external symbol CSourceSeeking::CSourceSeeking(…) despite linking with the right library 未解决的外部 - Unresolved Externals 未解决的外部问题,缺少 comdlg32.lib 库 - Unresolved externals, Missing comdlg32.lib library 删除了C运行时库,我收到了一些未解决的外部消息 - Removed the C runtime library, and i am receiving some unresolved externals Visual Studio(f2c)中带有静态库的未解决外部组件 - Unresolved externals with static library in Visual Studio (f2c) Catch库无法解析的外部符号 - Unresolved external symbol with Catch library Visual Studio 2013错误LNK1120:1未解决的外部和错误LNK2019:未解决的外部符号 - visual studio 2013 error LNK1120: 1 unresolved externals and error LNK2019: unresolved external symbol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM