开发者

DLL and Name Mangling

开发者 https://www.devze.com 2023-03-04 05:19 出处:网络
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.

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.

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:

开发者_JAVA百科

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

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).

Thanks.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消