DLL 和名称修改 [英] DLL and Name Mangling

查看:44
本文介绍了DLL 和名称修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方 LIB,它具有导出为普通 C/cdecl 的符号,因此例如 dumpbin.exe/SYMBOLS 报告 __imp_nvmlInitnvmlInit 被导出.

I have a third-party LIB which has symbols exported as plain C/cdecl, so for example dumpbin.exe /SYMBOLS reports that both __imp_nvmlInit and nvmlInit are exported.

但是在 Visual Studio 2010 中,当我尝试导入它们时,头文件将具有

However in Visual Studio 2010 when I try to import them, the header file will have

extern "C" nvmlReturn_t nvmlInit(...);

但是当我尝试编译时,出现以下错误:

but when I try to compile, I get the following error:

main.obj : error LNK2019: 未解析的外部符号 _nvmlInit 在函数 _main 中引用

main.obj : error LNK2019: unresolved external symbol _nvmlInit referenced in function _main

如何阻止 Visual Studio 查找带有前导下划线的符号?__declspect(dllimport) 不起作用,因为它会修饰为 __imp__nvmlInit(一个下划线太多).

How can I stop Visual Studio from looking for that symbol with a leading underscore? __declspect(dllimport) doesn't work because then it decorates to __imp__nvmlInit (one underscore too many).

谢谢.

推荐答案

这是一个链接器错误.您需要链接与 DLL 关联的 .LIB 文件,这将向链接器保证该函数将在加载 DLL 本身时在运行时可用.

That is a linker error. You need to link with the .LIB file associated with DLL, which will give the linker a promise that the function will be available at run-time when the DLL itself is loaded.

这篇关于DLL 和名称修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆