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 nvmlInit is 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? I thought the extern "C" was supposed to stop that.

Thanks.
The syntax is incorrect. The actual syntax varies between compilers, for example with Microsoft C/C++ on win32, the prefix syntax is
 
__declspec(dllimport)
... or you could use LoadLibrary() and GetProcAdress() if you have 3rd-party DLL and know function prototype.
__declspec(dllimport) decorates the name to __imp__nvmlInit (two underscores)

which is not what I want either. In fact the LIB exports names in both
__imp_nvmlInit (one underscore between imp and nvmlInit) and nvmlInit, but not __imp__nvmlInit (two underscores) nor _nvmlInit

I am using Visual Studio 2010.
Last edited on
You still have to use extern "C" you know.
Yes I know, what I'm trying to say is extern "C" nvmlReturn_t __declspec(dllimport) nvmlInit(...); will try to resolve __imp__nvmlInit whereas the exported function is really __imp_nvmlInit.
Mmm, I'm out of ideas. You'll have to load it at runtime as modoran suggested.
Topic archived. No new replies allowed.