I'm trying to build libffi using VC++. Apparently, this is possible (albeit from a command line) but only if I first install Cygwin, MSYS and MinGW.
If all else fails I suppose I'll have to install them but I'd prefer to create a vcproj if possible. I created a suitable project and as it happened, I only encountered one module that won't compile. Unusually, the module is called win32.S and looks something like this:-
;; cdecl: we restore esp in the epilogue, so there's no need to
;; remove the space we pushed for the args.
;; stdcall: the callee has already cleaned the stack.
;; Load ecx with the return type code
mov ecx, cif_flags
;; If the return value pointer is NULL, assume no return value.
cmp rvalue, 0
jne ca_jumptable
;; Even if there is no space for the return value, we are
;; obliged to handle floating-point values.
cmp ecx, FFI_TYPE_FLOAT
jne ca_epilogue
fstp st(0)
ca_retint8:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
mov [ecx + 0], al
jmp ca_epilogue
ca_retint16:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
mov [ecx + 0], ax
jmp ca_epilogue
ca_retint:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
mov [ecx + 0], eax
jmp ca_epilogue
ca_retint64:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
mov [ecx + 0], eax
mov [ecx + 4], edx
jmp ca_epilogue
ca_retfloat:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
fstp DWORD PTR [ecx]
jmp ca_epilogue
ca_retdouble:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
fstp QWORD PTR [ecx]
jmp ca_epilogue
ca_retlongdouble:
;; Load %ecx with the pointer to storage for the return value
mov ecx, rvalue
fstp TBYTE PTR [ecx]
jmp ca_epilogue
ca_epilogue:
;; Epilogue code is autogenerated.
ret
ffi_call_win32 ENDP
// Some more stuff
#endif
I've only shown the first function (there are a few others). As you can see, it's a strange mixture of C and x86 assembly code but the presence of #ifdef _MSC_VER near the top of the file suggests to me that it should be buildable with MSVC. However, VS2005 doesn't seem to like it very much (at least, not from within the IDE).
What would I need to do to compile and link this module? Do I need to pre-process it somehow? Or can it only be built from a command line? Or do I need a more recent version of Visual Studio?
December 6th, 2012, 12:50 PM
John E
Re: A ".S" file
My newly found friend, the pre-build step rescued me again. All I needed to do was run this pre-build step:-
cl /EP win32.S > win32.asm
and then I simply compiled the resultant .asm file. :thumb: