3

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.

agf
  • 148,965
  • 36
  • 267
  • 227
Andrew Lee
  • 2,365
  • 2
  • 18
  • 28

1 Answers1

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.

  • Oops, sorry I made a mistake in my original post -- I am actually linking to the .LIB, and the library exports completely undecorated functions whereas the linker is looking for underscore prepended names... – Andrew Lee May 11 '11 at 08:57