   _linking _problems
  I am trying to import some functions from a DLL namely cg.dll like so with a lib file:#pragma comment(lib,"cg")extern "C"{    CGcontext cgCreateContext(void);}or with an import DEF file. Either way the compiler tells me that there is an unresolved external '_cgCreateContext' which is annoying since I don't want it to look for that name with an underscore in front of the name in the DLL. Does anyone see what I'm doing wrong or any possible work arounds such as mapping one name onto the other?   
  maybe it should be: #pragma comment(lib,"cg.lib");Quote:Original post by paulbirdEither way the compiler tells me that there is an unresolved external '_cgCreateContext' which is annoying since I don't want it to look for that name with an underscore in front of the name in the DLL.When you write a function named foo() in C, the compiler internally knows it as _foo. It's part of the C ABI.C++ does even more extensive name mangling.   ;  When I add an import definition file:IMPORTS  _cgCreateContextthere is no longer the unresolved external error but now it can't find the entry point for _cgCreateContext in the DLL. Even though cgCreateContext is in the DLL.----I've resorted to having to load each function manually by loading the module cg.DLL at runtime:TModule *cg=new TModule("cg");cgCreateContext =  (CGcontext(*)(void)) cg->GetProcAddress("cgCreateContext");which works fine although it is clearly not the simplest way to do it. Is there no way to stop the compiler adding an _ onto the functions?[Edited by - paulbird on June 20, 2006 4:10:29 PM];Quote:Original post by paulbirdIs there no way to stop the compiler adding an _ onto the functions?No. It's part of the C language binary interface. User-defined symbols all get prefixed with an underscore.   ;Quote:Original post by paulbirdEither way the compiler tells me that there is an unresolved external '_cgCreateContext' which is annoying since I don't want it to look for that name with an underscore in front of the name in the DLL. Does anyone see what I'm doing wrong or any possible work arounds such as mapping one name onto the other?Here is a little article about calling conventions on CodeProject (it also provides information about name decorations).As i understand it, your DLL uses different default calling convention then your EXE. So compiler (linker, actualy) looks for differently decorated names. Try to add __cdecl (or __stdcall) to the public header of your DLL.   