Justin
Justin

Reputation: 4853

Error opening C++ shared library as Erlang port driver

I'm using Ubuntu 18:04 and have this C++ shared library I want to work with from a dynamic language.

The shared library is available from here -

http://www.warmplace.ru/soft/sunvox/sunvox_lib-1.9.4c.zip

It's a small embedded synthesizer - having extracted the zipfile I'm using sunvox_lib/linux/lib_x86/sunvox.so and changing permissions via chmod 755.

It works fine with Python 3.6 via ctypes, so I don't think it is corrupted -

(sv_demo) justin@justin-XPS-13-9360:~/work/sv_demo$ python
Python 3.6.8 (default, Dec 24 2018, 19:24:27) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> sv.sv_init(0, 44100, 2, 0) 
Desired audio buffer size: 2048 frames
ALSA: pulse
ALSA HW Default rate: 44100
ALSA HW Rate: 44100 frames
ALSA HW Buffer size: 4096 frames
ALSA HW Period size: 227
ALSA HW Periods: 0
ALSA SW Avail min: 227
ALSA SW Start threshold: 1   
ALSA SW Stop threshold: 4096
67844
>>> sv.sv_deinit()
SOUND: sundog_sound_deinit() begin
SOUND: sundog_sound_deinit() end
Max memory used: 41823
0
>>> exit()
(sv_demo) justin@justin-XPS-13-9360:~/work/sv_demo$ 

However I really want/need to use Erlang for this, not Python; and was hoping to do so via the port driver mechanism. But -

(sv_demo) justin@justin-XPS-13-9360:~/work/sv_demo$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]    
Eshell V9.3  (abort with ^G)
1> erl_ddll:load_driver(".", "sunvox.so").
{error,{open_error,-10}}

What might {open_error, -10} mean? I've worked with port drivers before and not had this problem. I have Googled around a bit but am unable to find a reason why Python is happy to work with it but Erlang not.

Any thoughts ?

TIA


Update.

2> erl_ddll:format_error({open_error, -10}).
"cannot open shared object file: No such file or directory"

Why can't it find sunvox.so? It's sitting there in the directory root from which I'm running erl ...

Upvotes: 2

Views: 260

Answers (3)

fregate
fregate

Reputation: 11

Try to

erl_ddll:load_driver(".", "sunvox").
  • without '.so' extension.

Upvotes: 1

From the documentation erl_dll, erl_dll:load_driver is to load a linked in driver. Linked driver's are libraries built with a specific set of interfaces...which I guess the shared library would not have implemented.

One option is to create a NIF's using the shared library and call the NIF's from erlang. The NIF's just need to wrap the functions you would like to use from the shared library

Upvotes: 2

Justin
Justin

Reputation: 4853

I think I'm calling the shared object with the wrong handle - you need to drop the .so suffix -

Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
1> erl_ddll:load_driver(".", "sunvox").   
{error,no_driver_init}
2> erl_ddll:format_error(no_driver_init).         
"No driver init in dynamic library"
3> 

Back to the drawing board :-(

Upvotes: 2

Related Questions