I use the libusb-1 with Windows 32/64-bit, and with Linux 64-bit and Raspberry PI 64-bit without any problems. When compiling, I can switch between prototypes with OpenLibrary() and ImportC. The assembler and C backend work without errors.
Under Linux 32-bit my program does not work with the prototypes and OpenLibrary() with the assembler backend.
There is a memory error 'Invalid memory access' at the first call of a function from the libusb-1. The program works with the C backend. The ImportC version also works with both backends.
Here in the example code, the error occurs when the 'Init()' function is ended.
There is a code with the libusb-1 from infratec:
https://www.purebasic.fr/english/viewtopic.php?p=633916
With the file 'libusb.pbi' there is exactly the same error in the 'libusb_init(*ctx)' procedure.
At the moment I don't understand where the error are coming from.
Peter
Code: Select all
EnableExplicit
#Prototype = 1 ; 1 for Prototype, 0 = for ImportC
CompilerIf #Prototype
Prototype.l ptLibusb_init(*Context)
Global libusb_init.ptLibusb_init
CompilerElse
ImportC "-lusb-1.0"
libusb_init.l(*Context)
EndImport
CompilerEndIf
CompilerIf #Prototype
Procedure.i LoadLibrary()
Protected fReturn.i, iLib.i
iLib = OpenLibrary(#PB_Any, "libusb-1.0.so.0")
If iLib
libusb_init = GetFunction(iLib, "libusb_init")
fReturn = #True
EndIf
ProcedureReturn fReturn
EndProcedure
CompilerEndIf
Procedure.i Init()
Protected iError.l
iError = libusb_init(#Null)
ProcedureReturn iError
EndProcedure
Define iError.i
CompilerIf #Prototype
If LoadLibrary()
iError = Init()
Debug iError
EndIf
CompilerElse
iError = Init()
Debug iError
CompilerEndIf