views:

80

answers:

1

In VS2005, I was using _cdecl calling convention and the project builds without any linker errors. After I change the calling convention to _stdcall while porting the project to VS2008, I get the following error:

error LNK2001: unresolved external symbol _imp_GCBOpen@8.

Configuration Settings>C\C++>Genral>Common Language Runtime support is set to No Common Language Runtime support

I need help regarding any project settings or code changes that need to be done in order to resolve the issue. Any help is appreciated.

+1  A: 

It looks like GCBOpen() is compiled __cdecl but its declaration does not explicitly state that. (That's why it linked OK when your default was __cdecl but breaks when you change it.) In general it is good practice for declarations of functions in external libraries to specify the calling convention to avoid problems such as the one you have enountered.

Somewhere you must have something like:

__declspec(dllimport)
extern int GCBOpen(int, int);

which would be better off as:

#define CALLCONV __cdecl
__declspec(dllimport)
extern int CALLCONV GCBOpen(int, int);
Brian Nixon
Thankyou for the reply. It actaullay solved the issue. I still have a question.Since GCBOpen is an imported function, the function declaration should have had "extern" keyword.Why did the code compile without specifying "extern" when the calling convention is __cdecl?
Lakshmi
`extern` is assumed for function declarations that aren't `static`, so you don't need to specify it explicitly. I don't know why I persist in writing it in my own declarations...
Brian Nixon