cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Support calling convention specification

Open mattiekat opened this issue 4 years ago • 3 comments

I am a native rust coder so take this with a grain of salt:

My understanding is that when you are creating a library it is best practice to define the calling convention because someone may be using a different default and then when they try to link with your code it will fail without first re-writing your header.

It should be possible to just add __cdecl if it is extern "C" or __stdcall if it is extern "stdcall" and so on.

Specifically the request here is to allow explicitly saying __cdecl on functions, since right now function prefix/postfix settings won't allow putting this into the declarations.

mattiekat avatar Oct 12 '21 19:10 mattiekat

Relates to #55

mattiekat avatar Oct 12 '21 19:10 mattiekat

It would be useful to always specify the calling convention.

I came across this issue because I hit linker errors with unresolved externals because somebody was passing the /Gz flag to VC++. This option says "make all unannotated functions stdcall" and my Rust functions were compiled with the default (cdecl).

For now I think my only option is to edit the cbindgen generated header because I can't know which compiler flags will be used.

lzybkr avatar May 02 '22 22:05 lzybkr

@lzybkr Feel free to send a patch with an option to specify the concrete calling convention, that seems like a reasonable use-case.

emilio avatar Jun 06 '22 21:06 emilio