LNK2001:我忘记设置什么了?

发布于 2024-08-27 03:31:29 字数 2133 浏览 12 评论 0原文

根据我关于调试本机代码的上一个问题,我决定创建一个简单的测试控制台应用程序,因为我无法直接调试服务。

因此,我创建了一个 vc6 控制台应用程序,将 dll 项目添加到工作区并运行它。

它没有按预期执行,而是抛出以下链接器错误:

 main.obj : error LNK2001: unresolved external symbol "int __stdcall hmDocumentLAdd(char *,char *,long,char *,char *,long,long,long,long *)" (?hmDocumentLAdd@@YGHPAD0J00JJJPAJ@Z)
 main.obj : error LNK2001: unresolved external symbol "int __stdcall hmGetDocBasePath(char *,long)" (?hmGetDocBasePath@@YGHPADJ@Z)
 Debug/HazManTest.exe : fatal error LNK1120: 2 unresolved externals

这似乎是忘记链接器选项中某些内容的简单情况:但是一切似乎都很正常,并且 lib 文件、dll 和源代码可用。如果我将 lib 文件更改为无意义加载,则会引发致命错误 LNK1104:无法打开文件“asdf.lib”,因此这不是问题。

我之前已经链接到 dll 并且它们刚刚工作,那么我忘记做什么?

更新:按照 此线程 我查看是否可以找到任何其他信息。这就是 VS2005 的 dumpbin 给我的。

> dumpbin /linkermember Hazardman.lib | findstr "DocumentLAdd"
     F6DC __imp__hmDocumentLAdd@36
     F6DC _hmDocumentLAdd@36
       5B __imp__hmDocumentLAdd@36
       5B _hmDocumentLAdd@36

然后通过 unname 运行它会导致:

> undname ?_hmDocumentLAdd@36
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "?_hmDocumentLAdd@36"
is :- "?_hmDocumentLAdd@36"

这是错误的。如果我输入 IDE 中的损坏名称,它会给出更好的结果:

> undname ?hmDocumentLAdd@@YGHPAD0J00JJJPAJ@Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "?hmDocumentLAdd@@YGHPAD0J00JJJPAJ@Z"
is :- "int __stdcall hmDocumentLAdd(char *,char *,long,char *,char *,long,long,l
ong,long *)"

现在我有了这些信息,我可以用它做什么?从这篇 Raymond Chen 文章看来,我可以手动修复它但调整一个选项,但我无法从结果中辨别出需要什么选项(是否有“忽略所有参数”复选框?!)。

所以看起来它正在寻找不存在的函数或者函数的参数已被省略(或者 dumpbin 不喜欢 VC6 库),但它仍然没有让我更接近解决问题的目标。

Following on from my previous question regarding debugging of native code, I decided to create a simple test from a console app as I wasn't getting anywhere with debugging the service directly.

So I created a vc6 console app, added the dll project to the workspace and ran it.

Instead of executing as expected it spat out the following linker errors:

 main.obj : error LNK2001: unresolved external symbol "int __stdcall hmDocumentLAdd(char *,char *,long,char *,char *,long,long,long,long *)" (?hmDocumentLAdd@@YGHPAD0J00JJJPAJ@Z)
 main.obj : error LNK2001: unresolved external symbol "int __stdcall hmGetDocBasePath(char *,long)" (?hmGetDocBasePath@@YGHPADJ@Z)
 Debug/HazManTest.exe : fatal error LNK1120: 2 unresolved externals

This seems to be a simple case of forgetting something in the linker options: However everything seems to be normal, and the lib file, dll and source is available. If I change the lib file to load to nonsense it kicks up the fatal error LNK1104: cannot open file "asdf.lib", so that isn't a problem.

I have previously linked to dll and they have just worked, so what I have forgotton to do?

Update: As per this thread I looked to see if I could find out any additional information. This is what dumpbin from VS2005 gives me.

> dumpbin /linkermember Hazardman.lib | findstr "DocumentLAdd"
     F6DC __imp__hmDocumentLAdd@36
     F6DC _hmDocumentLAdd@36
       5B __imp__hmDocumentLAdd@36
       5B _hmDocumentLAdd@36

Then running it through undname results in:

> undname ?_hmDocumentLAdd@36
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "?_hmDocumentLAdd@36"
is :- "?_hmDocumentLAdd@36"

Which is wrong. If I put in the mangled name from the IDE it gives the lot better result of:

> undname ?hmDocumentLAdd@@YGHPAD0J00JJJPAJ@Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "?hmDocumentLAdd@@YGHPAD0J00JJJPAJ@Z"
is :- "int __stdcall hmDocumentLAdd(char *,char *,long,char *,char *,long,long,l
ong,long *)"

Now I have this information, what can I do with it? It seems from this Raymond Chen article I can manually fix it but tweaking an option, but my I can't discern from my results what option is needed (is there an 'ignore all parameters' checkbox?!).

So it seems that it is looking for non-existant functions or the parameters of the function have been left off (or dumpbin doesn't like VC6 libs), but it stil doesn't get me nearer my goal of fixing my problem.

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

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

发布评论

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

评论(1

迷你仙 2024-09-03 03:31:29

您是否使用了正确的调用约定
您的库似乎使用 stdcall。也许您的测试代码正在使用 cdecl (似乎是默认值)。

根据此页面,链接器名称装饰在校准约定之间有所不同所以这可以解释您所看到的症状。

Are you using the correct calling convention?
Your library appears to use stdcall. Maybe your test code is using cdecl (appears to be the default).

According to this page, the linker name decorations differ between the caling conventions so this can explain the symptoms you are seeing.

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