DLL and Name Mangling

May 11, 2011 at 7:00pm
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.
May 11, 2011 at 7:05pm
The syntax is incorrect. The actual syntax varies between compilers, for example with Microsoft C/C++ on win32, the prefix syntax is
 
__declspec(dllimport)
May 11, 2011 at 7:15pm
... or you could use LoadLibrary() and GetProcAdress() if you have 3rd-party DLL and know function prototype.
May 11, 2011 at 7:55pm
__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 May 11, 2011 at 7:57pm
May 11, 2011 at 8:49pm
You still have to use extern "C" you know.
May 11, 2011 at 9:51pm
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.
May 11, 2011 at 10:05pm
Mmm, I'm out of ideas. You'll have to load it at runtime as modoran suggested.
Topic archived. No new replies allowed.