Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-11

Linking to an arbitrary DLL (libusb-win32)

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

Out of curiosity I'm trying to press ahead a bit further with linking a Lazarus program that runs successfully with libusb to run instead with libusb-win32. I know that there will be runtime problems since I'm trying to run on NT4 but I'm interested to see to what extent I can get additional error messages etc. out of the system.

When compiled for Linux I've got a simple unit UsbIf that calls Uwe Zimmerman's translation of libusb.h which includes

{$linklib usb}
..
procedure usb_set_debug(level: longint);cdecl;external;

On the Windows systems the DLL is libusb0.dll and in principle I've got .h files etc. available. When I compile I get

Error: Import library not found for usb
..
Error: Undefined symbol _usb_set_debug

It's 20 years since I've played with import libraries, and before I start tinkering I need to know that I'm not heading off in the wrong direction.

This is in no way important, but what should I be doing to get this to link against the available DLL?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Sergei Gorelkin
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 18 lines
... When compiled for Linux I've got a simple unit UsbIf that calls Uwe Zimmerman's translation of libusb.h which includes {$linklib usb} .. procedure usb_set_debug(level: longint);cdecl;external; On the Windows systems the DLL is libusb0.dll and in principle I've got .h files etc. available. When I compile I get Error: Import library not found for usb .. Error: Undefined symbol _usb_set_debug It's 20 years since I've played with import libraries, and before I start tinkering I need to know that I'm not heading off in the wrong direction.

Having faced with the same problem in the meantime, I deleted the {$linklib } directive and added library and name to all function definitions, so your example would look like

procedure usb_set_debug(level: longint);cdecl;external libname name
'usb_set_debug';

The libname constant has to be defined differently for Windows and Linux:

const
{$IFDEF MSWINDOWS}
   libname = 'libusb0.dll';
{$ELSE}
   libname = 'libusb.so';
{$ENDIF}

Another caveat with libusb-win32 is that LIBUSB_PATH_MAX constant should be different from the Linux one:

{$IFDEF MSWINDOWS}
const LIBUSB_PATH_MAX = 512;
{$ENDIF}
{$IFDEF LINUX}
const LIBUSB_PATH_MAX = 4097;
{$ENDIF}

Regards,
Sergei

Reply by email

Mark Morgan Lloyd
to Sergei Gorelkin
Sergei Gorelkin wrote 25 lines
Having faced with the same problem in the meantime, I deleted the {$linklib } directive and added library and name to all function definitions, so your example would look like procedure usb_set_debug(level: longint);cdecl;external libname name 'usb_set_debug'; The libname constant has to be defined differently for Windows and Linux: const {$IFDEF MSWINDOWS} libname = 'libusb0.dll'; {$ELSE} libname = 'libusb.so'; {$ENDIF} Another caveat with libusb-win32 is that LIBUSB_PATH_MAX constant should be different from the Linux one: {$IFDEF MSWINDOWS} const LIBUSB_PATH_MAX = 512; {$ENDIF} {$IFDEF LINUX} const LIBUSB_PATH_MAX = 4097; {$ENDIF}

Thanks Sergei, I'll investigate. I've also come across a toolset called usbio which is expensive but available for a limited-time evaluation (four hours per session) and apparently includes Delphi support. I'm not expecting to get very far, but I'm interested to see just how much functionality the Edgeport stuff grafts onto NT4.

http://www.thesycon.de/eng/usbio_demo.shtml
http://www.digi.com/support/productdetl.jsp?pid=2628&osvid=55&tp=1&s=0

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email