Search code examples
smalltalkpharo

Where to put the shared library (*.so) to avoid "Error: External module not found"


I created a new code in C Programming and created a shared library out of it. I want to access it on Pharo 7. So I put it on /usr/local/lib , /usr/lib and even on the folder where Pharo executable file located. When I run the code I always get an "Error: External module not found". Where should I put properly the *.so library. I run the Pharo 7 in Raspberry Pi 3 Model B+ with a Raspbian Stretch OS. Here is my code:

'From Pharo7.0.1 of 25 February 2019 [Build information: Pharo-7.0.1+build.149.sha.890f474a81f116ead0e68c8de77790aef4e9a752 (32 Bit)] on 9 May 2019 at 2:29:46.092395 pm'!
FFILibrary subclass: #AD7091RFFILibrary
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Manifold-AD7091R'!

!AD7091RFFILibrary methodsFor: 'accessing platform' stamp: 'LesterLecong 5/9/2019 14:01'!
unixModuleName
    "Kept for backward compatibility. 
     Users should use unix32* or unix64*"
    ^ 'AD7091R.so'! !

!AD7091RFFILibrary methodsFor: 'accessing platform' stamp: 'LesterLecong 5/9/2019 11:49'!
macModuleName 
    ^ 'AD7091R.dylib'! !

!AD7091RFFILibrary methodsFor: 'accessing platform' stamp: 'LesterLecong 5/9/2019 11:50'!
win32ModuleName 
    ^ 'AD7091R.dll'! !

!AD7091RFFILibrary methodsFor: 'accessing platform' stamp: 'LesterLecong 5/9/2019 14:01'!
unix32ModuleName
    "Kept for backward compatibility. 
     Users should use unix32* or unix64*"
    ^ 'AD7091R.so'! !


!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:01'!
apiAD7091RDealloc: handle
    "int AD7091R_dealloc(AD7091R *p_instance)"
    ^ self ffiCall: #(int AD7091R_dealloc(AD7091RExternalObject handle))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:13'!
apiAD7091RData: handle pin: pin
    "iint AD7091R_data_pin(AD7091R *p_instance,
                         uint8_t n_data_pin)"
    ^ self ffiCall: #(int AD7091R_data_pin(AD7091RExternalObject handle, int pin))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 11:57'!
apiAD7091RAlloc: handle
    "int AD7091R_alloc(AD7091R **pp_instance)"
    ^ self ffiCall: #(int AD7091R_alloc(AD7091RExternalObject *handle))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 13:12'!
apiAD7091RPins: handle convst: convstPin cs: csPin clk: clkPin data: dataPin
    "int AD7091R_pins(AD7091R *p_instance, 
                      uint8_t n_convst_pin,
                     uint8_t n_cs_pin,
                     uint8_t n_clk_pin,
                     uint8_t n_data_pin)"
    ^self ffiCall: #(int AD7091R_pins(AD7091RExternalObject handle, 
                                       int convstPin, 
                                       int csPin, 
                                                 int clkPin, 
                                                 int dataPin))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:14'!
apiAD7091RBegin: handle
    "iint AD7091R_begin(AD7091R *p_instance)"

    ^ self ffiCall: #(int AD7091R_begin(AD7091RExternalObject handle))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:11'!
apiAD7091RClk: handle pin: pin
    "iint AD7091R_clk_pin(AD7091R *p_instance,
                         uint8_t n_clk_pin)"
    ^ self ffiCall: #(int AD7091R_clk_pin(AD7091RExternalObject handle, int pin))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:11'!
apiAD7091RConvst: handle pin: pin
    "iint AD7091R_convst_pin(AD7091R *p_instance,
                             uint8_t n_convst_pin)"
    ^ self ffiCall: #(int AD7091R_convst_pin(AD7091RExternalObject handle, int pin))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:12'!
apiAD7091RCs: handle pin: pin
    "iint AD7091R_cs_pin(AD7091R *p_instance,
                         uint8_t n_cs_pin)"
    ^ self ffiCall: #(int AD7091R_cs_pin(AD7091RExternalObject handle, int pin))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:16'!
apiAD7091RData: handle
    "iint AD7091R_data(AD7091R *p_instance)"

    ^ self ffiCall: #(int AD7091R_data(AD7091RExternalObject handle))! !

!AD7091RFFILibrary methodsFor: 'api' stamp: 'LesterLecong 5/9/2019 12:16'!
apiAD7091RReset: handle
    "iint AD7091R_reset(AD7091R *p_instance)"

    ^ self ffiCall: #(int AD7091R_reset(AD7091RExternalObject handle))! !

Solution

  • I generally recommend putting library files in the the VM's lib folder. So for a Pharo 6 distro I have handy, it would go in the pharo6.0-64/bin/lib/pharo/5.0-201705310241 directory. (The exact subdirectory names will vary a bit from version to version since they embed version numbers.) Also, you can usually get away with symlinking to the library rather than copying it.