Call C shared library function from LibreOffice Basic (Calc)

Question concerning LibreOffice Calc 4.2.3.3, Build ID 420m0 (Build: 3) on 64-bit Kubuntu Linux 14.04.

I’m trying to call a C shared library function from LibreOffice Basic, but I always get “Basic Runtime Error. Not implemented” when it hits the Declare line. It’s just for a fun thing but being unable to do it is bugging me.

The Declare statement looks like this:

Declare Function score_word Lib "libscrabblescore.so" Alias "score_word" (ByRef word As String, ByRef bonus As String) As Integer

The C function delaration looks like this:

int score_word(char* word, char* word_bonuses)

(Maybe ByRef word As String is not the right translation of char* word? I can’t find documentation on how to use char* parameters to functions from LibreOffice Basic.)

I validated the shared library itself by calling it using Python’s ctypes module:

>>> from ctypes import CDLL
>>> lib = CDLL("/usr/lib/libscrabblescore.so")
>>> lib.score_word("qi", "dw dlq")
42
>>> 

(So I have the “Answer to the Ultimate Question of Life, the Universe, and Everything,” just not for how to do this in LibreOffice Basic!)

I tried using the absolute path in the Declare statement as well, and it made no difference.

I found a Windows thread on the topic of calling DLL’s where the asker said he needed to put the DLL in a specific location (the LibreOffice bin directory) so LibreOffice could access it. There is no LibreOffice bin directory per-se on Linux, and unfortunately there are 351 candidate directories I was able to identify on my machine (my path, and all folders with “libreoffice” in the name or under a folder with “libreoffice” in the name).

I tried a shotgun approach and put a symbolic link to the shared library in all 351 directories, but then Calc hangs on startup. So I removed those, started Calc, and put them all back in place and tried the function. If it was a location thing, you’d think that would work as LibreOffice Basic is supposed to load the library at the point of the Declare. Still no luck.

So, has anybody ever successfully called a C shared library function from a LibreOffice Basic program that knows what I’m doing wrong? Thanks!

Don’t the ByRef, ByVal, and As ... interpretives belong in the Sub? I don’t think they are required in the calling statement. Something like score_word(word, bonus) should be sufficient, unless C has particular requirements. I am not clear on the linking / include requirements or possibility, so this may all be ancillary.

“no LibreOffice bin directory per-se on Linux” On Windows 7 there is ´/URE/bin`, isn’t there something similar on Linux?

@Regina, here under Debian I have an /opt/libreoffice4.X/program/fundamentalrc file which contains a line: URE_BIN_DIR=${BRAND_BASE_DIR}/ure-link/bin that appears to effectively point to /opt/libreoffice4.X/ure/bin (as ure-link/ is a symbolic link to ure/).