Andrew Lee
Andrew Lee

Reputation: 2603

DLL and Name Mangling

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.

Upvotes: 3

Views: 921

Answers (1)

user2100815
user2100815

Reputation:

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.

Upvotes: 1

Related Questions