Archived Forum PostQuestion:
Chilkat Purebasic module can't work in x86 (32bits) Linux OS, it works only for x86_64.
When I try to run it on 32-bit Linux, I get an Access Violation.
I tested on 32-bit Linux and found the same problem. However, the access violation is caused by the OpenLibrary call failing to find the libchilkatPb32-9_5_0.so.
Each Chilkat PureBasic module (such as CkCrypt2.pb), contains the following snippet of code to load the shared library:
...
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "chilkatPb32-9_5_0.dll")
CompilerElse
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "chilkatPb-9_5_0.dll")
CompilerEndIf
CompilerCase #PB_OS_MacOS
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "libchilkatPb-9_5_0.dylib")
CompilerCase #PB_OS_Linux
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "libchilkatPb32-9_5_0.so")
CompilerElse
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "libchilkatPb-9_5_0.so")
CompilerEndIf
CompilerEndSelect
...
If a full directory path to the .so is provided, then PureBasic will find the shared library. For example:
...
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "chilkatPb32-9_5_0.dll")
CompilerElse
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "chilkatPb-9_5_0.dll")
CompilerEndIf
CompilerCase #PB_OS_MacOS
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "libchilkatPb-9_5_0.dylib")
CompilerCase #PB_OS_Linux
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "/home/someUser/chilkat/libchilkatPb32-9_5_0.so")
CompilerElse
CkCrypt2LibId.i = OpenLibrary(#PB_Any, "/home/someUser/chilkat/libchilkatPb-9_5_0.so")
CompilerEndIf
CompilerEndSelect
...
If the .so filepath passed to OpenLibrary does not include a path, then the operating system will search for the library in its system folders, the applications directory and the current directory. If it is not found, then OpenLibrary returns 0.
The solution is to make sure the .so is located in a directory where the operating system will find it, or to specify the full path to the .so in the .pb module.
Also, code that creates a new Chilkat object can check the return value to see if it was successful. If not, then it most likely means the library (.so) could not be found.
crypt.i = CkCrypt2::ckCreate()
If crypt.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf