Linker Errors and stdcall vs cdecl calling conventions (VC++ 2008)

203 views
Skip to first unread message

Kostya Y

unread,
Mar 15, 2011, 8:05:38 AM3/15/11
to Protocol Buffers
Hello
It seems like the calling convention used in libprotobuf's vc project
is cdecl while the Microsoft's preferred way (or the default one) is
stdcall.

Is there a reason why cdecl was chosen?
I am getting linker errors as the functions are not strictly defined
as cdelc so the linker assumes that it should use default project
settings which in my case is stdcall. As a result I get the following
errors:
error LNK2001: unresolved external symbol "void __stdcall
google::protobuf::internal::VerifyVersion(int,int,char const *)" (?
VerifyVersion@internal@protobuf@google@@YGXHHPBD@Z)

As you can see it expects it to be __stdcall (projects settings are
set to default naming convention stdcall) while it is exported as
cdecl.

Any suggestions how to work around it?
Thanks
- Kostya

Kostya Y

unread,
Mar 16, 2011, 5:01:30 AM3/16/11
to Protocol Buffers
At the moment I solved this problem by recompiling protobuf with
stdcall calling conventions.

Are there any issues that can arise from this? If so which?

Thanks

Kenton Varda

unread,
Mar 24, 2011, 11:58:41 AM3/24/11
to Kostya Y, Protocol Buffers
We never actually "chose" to use cdecl; it was simply the default used by MSVC.  This whole idea that the programmer should have to choose between calling conventions is a bit strange and inconvenient.  The LIBPROTOBUF_EXPORT annotations are annoying enough; I hope we don't have to litter our code with calling convention annotations as well.  Is there any way we can modify the existing LIBPROTOBUF_EXPORT macro to specify calling conventions too?

Your work-around of compiling the DLL with different settings should work fine.  I can't imagine any reason why stdcall would cause problems.  Out of curiosity, what is the binary size difference between the cdecl version and the stdcall version?  The MSDN docs claim stdcall produces smaller binaries.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Reply all
Reply to author
Forward
0 new messages