PBv621b4 x86 - Error with Prototype and libusb-1
Posted: Tue Apr 08, 2025 8:41 am
PB v6.12/v6.20/v6.21b4 x86, LMDE 6
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 or c backend.
There is a memory error 'Invalid memory access' at the first call of a function from the libusb-1. The ImportC version works with both backends.
Here in the example code, the error occurs when the 'Init()' function is ended.
You may need to install the developer package if there is an error importing "-lusb-1.0".
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.
Peter
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 or c backend.
There is a memory error 'Invalid memory access' at the first call of a function from the libusb-1. The ImportC version works with both backends.
Here in the example code, the error occurs when the 'Init()' function is ended.
You may need to install the developer package if there is an error importing "-lusb-1.0".
Code: Select all
sudo apt install libusb-1.0-0-dev
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.
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