Loading a shared library with only Cling installed (no root)

Hello,

I am experimenting with Cling on a BeagleBone Black running the Bela interactive audio extensions (http://bela.io). I am interested in using the Cling interpreter for live coding of interactive audio devices and musical instruments.

I have successfully installed Cling on a Bela and am trying to load libbela:

.I /root/Bela/include
.I /usr/xenomai/bin/xeno-config --ldflags --skin=posix --no-auto-init
.L Bela.h
.x /root/Bela/core/cling_test.cpp

This results in unresolved while linking function [cling interface function] errors.

IncrementalExecutor::executeFunction: symbol 'gShouldStop' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_InitSettings_free' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_defaultSettings' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_usage' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_InitSettings_alloc' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_startAudio' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'render' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_initAudio' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_cleanupAudio' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'cleanup' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'Bela_stopAudio' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
IncrementalExecutor::executeFunction: symbol 'setup' unresolved while linking function '_GLOBAL__sub_I_cling_module_2'!
Error: unable to initialise audio
(int) 1

After searching on the forum it seems people are encouraged to load libraries like so: gSystem->Load("root/Bela/lib/libbela.so").

However, it seems Cling is not aware of gSystem:

[cling]$ gSystem
input_line_3:2:2: error: use of undeclared identifier 'gSystem'
 gSystem
 ^

I have checked this by installing full root on macOS 10.14 and successfully accessing gSystem.

I am also unable to do the following in a .cpp file:

R__ADD_LIBRARY_PATH(/root/Bela/lib/)
R__LOAD_LIBRARY(libbela.so)

Is it possible to load a library using just Cling as I’ve been attempting? The reason I’d like to avoid installing all of root on Bela is to avoid filling up my SD card and any CPU overhead of running root instead of just cling (assuming there is some).

Thanks!

cling_test.cpp (1.9 KB)

I’ve just been able to load the library via #pragma cling load("/root/Bela/lib/libbela.so"):

Awesome project!

.L /root/Bela/lib/libbela.so should work. Do that before loading cling_test.cpp. Or indeed, add the pragma to your source file. But then you can also convert .L Bela.h into an #include "Bela.h" in your source file.

I don’t think .I /usr/xenomai/bin/xeno-config --ldflags --skin=posix --no-auto-init has the effect you expect, see the output of .I which prints the include search paths.

Cheers, Axel

Hi Axel, thanks for your reply and for clarifying a few things.

This is where I’m currently up to:

[cling]$ .I /root/Bela/include
[cling]$ .L /root/Bela/lib/libbela.so
[cling]$ .x /root/Bela/projects/cling/cling_test.cpp
IncrementalExecutor::executeFunction: symbol 'setup' unresolved while linking function '_GLOBAL__sub_I_cling_module_1'!
IncrementalExecutor::executeFunction: symbol 'cleanup' unresolved while linking function '_GLOBAL__sub_I_cling_module_1'!
IncrementalExecutor::executeFunction: symbol 'render' unresolved while linking function '_GLOBAL__sub_I_cling_module_1'!
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Stack dump:
0.	Program arguments: cling
Aborted

setup, render and clean are three user-defined functions that make up a Bela program, similar to Arduino’s setup and loop:

BelaInitSettings* settings = Bela_InitSettings_alloc();	// Standard audio settings
Bela_defaultSettings(settings);
settings->setup = setup;
settings->render = render;
settings->cleanup = cleanup;
Bela_InitSettings_free(settings);

The settings are then used to call Bela_initAudio(settings, 0); which is where the std::bad_alloc is occurring (https://github.com/BelaPlatform/Bela/blob/master/core/RTAudio.cpp#L197).

Is std::bad_alloc a common error with Cling? Any idea what might be going wrong here?


The other issue I can see at the moment is that the Bela Makefile uses lots of default flags and libs: https://github.com/BelaPlatform/Bela/blob/master/Makefile#L280 & #L487

Do you have any suggestions for approaching this?


Regarding .I /usr/xenomai/bin/xeno-config --ldflags --skin=posix --no-auto-init

see the output of .I which prints the include search paths

-I
/root/Bela/include
-I
/usr/xenomai/bin/xeno-config --ldflags --skin=posix --no-auto-init

Is this incorrect then?

Thanks!

I am amazed to say that Cling works on Bela!

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ .I /root/Bela/include
[cling]$ .L /root/Bela/lib/libbela.so
[cling]$ .L /root/Bela/lib/libbelaextra.so
[cling]$ .x /root/Bela/projects/cling/cling_giulio.cpp
[cling]$ gFreq
[#float#]gFrequency
[cling]$ gFrequency = 880
(float) 880.000f
[cling]$ gFrequency = 1320
(float) 1320.00f
[cling]$ gFrequency = 1760
(float) 1760.00f
[cling]$

If it is of interest to the forum, I could continue to post here or in a new thread about where this goes?

Thanks for your help.

1 Like

Congrats!

You’re welcome to post - especially if there are any questions you have!

Regarding your earlier post:

No - /usr/xenomai/bin/xeno-config --ldflags --skin=posix --no-auto-init is not an include path; this will cause havoc.

The flags might not be a problem. The libs should ideally be linked into the bela library; ldd libBela (or whatever it’s called) should tell you: if that spits out a series of libraries Bela depends on then loading just libBela will also load everything it depends on.

Cheers, Axel.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.