DLL and Name Mangling

送分小仙女□ 提交于 2019-12-10 20:47:00

问题


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:

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.


回答1:


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.



来源:https://stackoverflow.com/questions/5960717/dll-and-name-mangling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!