[fpc-pascal] libusb header translation and OOP wrapper

Christo christo.crause at gmail.com
Fri Sep 28 22:21:06 CEST 2012


On Tue, 2012-09-25 at 22:16 +0100, Henry Vermaak wrote:
> On 25 September 2012 20:57, Christo <christo.crause at gmail.com> wrote:
> > Any ideas on how to define the calling convention in the import unit so
> > that it is either stdcall or cdecl depending on the target OS?
> 
> I've used a macro for this in the past.  E.g. :
> 
> {$macro on}
> {$ifdef windows}
>   {$define CCONV:=stdcall}
> {$else}
>   {$define CCONV:=cdecl}
> {$endif}

Thanks Henry, that macro worked.  I however have a problem statically
linking to the libusbx library on Windows. I've downloaded the Windows
libusbx 1.0.14 library from sourceforge and pointed the compiler to the
mingw32 folder containing libusb-1.0.a.  

It complains about undefined symbols such as: 
project1.lpr(18,1) Error: Undefined symbol: LIBUSB_LIBUSB_INIT
$PLIBUSB_CONTEXT$$LONGINT

I have changed the calling convention to cdecl and then it also
complains:  project1.lpr(18,1) Error: Undefined symbol: _libusb_init

I've managed to load the library dynamically using LoadLibrary and then
loading each function/procedure using GetProcedureAddress.  This works
both on windows and on Linux.

Anyone knows why the static linking fails on Windows XP sp2?  I'm using
fpc 2.6.0 and have also tried the MS32 .lib library with no success.




More information about the fpc-pascal mailing list