?- use_module(library(plosc)). ERROR:

50 views
Skip to first unread message

roberto morales

unread,
Aug 3, 2016, 1:41:56 PM8/3/16
to SWI-Prolog
Dear Swi-prolog users

I want to explore the osc feature to generate music in prolog and supercollider
compilation went ok but is not reading foreing_library(plosc)

any ideas?

===

pack_install(plosc).

% Contacting server at http://www.swi-prolog.org/pack/query ... ok

Install pl...@0.4.4 from https://code.soundsoftware.ac.uk/projects/plosc/repository/raw/release/plosc-0.4.4.tgz Y/n?

% Contacting server at http://www.swi-prolog.org/pack/query ... ok

% "plosc-0.4.4.tgz" was downloaded 6 times

Package: plosc

Title: OSC input/output via liblo

Installed version: 0.4.4

Author: Samer Abdallah <s.abd...@ucl.ac.uk>

Download URL: https://code.soundsoftware.ac.uk/projects/plosc/repository/raw/release/plosc-0.4.4.tgz

Install "plosc-0.4.4.tgz" (10,478 bytes) Y/n?

Warning: CC="gcc"

Warning: PLBASE="/Applications/SWI-Prolog.app/Contents/swipl"

Warning: PLARCH="x86_64-darwin14.3.0"

Warning: PLLIBS=""

Warning: PLLIB="-lswipl"

Warning: PLCFLAGS="-fno-strict-aliasing -pthread -fno-common"

Warning: PLLDFLAGS="-O2 -pthread"

Warning: PLSOEXT="dylib"

Warning: PLTHREADS="yes"

Warning: plosc.c:265:12: warning: variable 'f' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]

Warning: int ok = PL_get_int64(sec, &s) && PL_get_int64(frac, &f);

Warning: ^~~~~~~~~~~~~~~~~~~~~

Warning: plosc.c:267:13: note: uninitialized use occurs here

Warning: ts->frac = f;

Warning: ^

Warning: plosc.c:265:12: note: remove the '&&' if its condition is always true

Warning: int ok = PL_get_int64(sec, &s) && PL_get_int64(frac, &f);

Warning: ^~~~~~~~~~~~~~~~~~~~~~~~~

Warning: plosc.c:264:14: note: initialize the variable 'f' to silence this warning

Warning: int64_t s, f;

Warning: ^

Warning: = 0

Warning: plosc.c:828:12: warning: implicit declaration of function 'pthread_join' is invalid in C99 [-Wimplicit-function-declaration]

Warning: result = pthread_join( st->thread, NULL );

Warning: ^

Warning: plosc.c:848:12: warning: implicit declaration of function 'pthread_create' is invalid in C99 [-Wimplicit-function-declaration]

Warning: result = pthread_create(&(st->thread), NULL, (void *)&prolog_thread_func, st);

Warning: ^

Warning: plosc.c:884:2: warning: implicit declaration of function 'pthread_exit' is invalid in C99 [-Wimplicit-function-declaration]

Warning: pthread_exit(NULL);

Warning: ^

Warning: 4 warnings generated.

Warning: clang: warning: argument unused during compilation: '-pthread'

% make -C c

% /Applications/SWI-Prolog.app/Contents/swipl/bin/x86_64-darwin14.3.0/swipl-ld -v -I/opt/local/include -L/opt/local/lib -llo -fPIC -Wall -shared -o plosc.dylib plosc.c

% eval `swipl --dump-runtime-variables`

% gcc -c -fno-common -Wall -fno-common -fno-strict-aliasing -pthread -fno-common -D_REENTRANT -D__SWI_PROLOG__ -I/Applications/SWI-Prolog.app/Contents/swipl/include -I/opt/local/include -o plosc.o plosc.c

% gcc -o plosc.dylib -bundle -dynamic -flat_namespace -undefined suppress -O2 -pthread plosc.o -L/Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin14.3.0 -L/opt/local/lib -llo -lswipl

% rm plosc.o

% strip -x plosc.dylib

% echo "No checks defined."

% No checks defined.

% make -C c

% make[1]: Nothing to be done for `main'.

% install -d lib/x86_64-darwin14.3.0

% install -bCS c/plosc.dylib lib/x86_64-darwin14.3.0

true.



====

?- use_module(library(plosc)).

ERROR: /Applications/SWI-Prolog.app/Contents/swipl/pack/plosc/prolog/plosc.pl:36:

'$open_shared_object'/3: dlopen(/Applications/SWI-Prolog.app/Contents/swipl/pack/plosc/lib/x86_64-darwin14.3.0/plosc.dylib, 1): Library not loaded: /Users/janw/stable/lib/swipl-7.2.3/lib/x86_64-darwin14.3.0/libswipl.dylib

Referenced from: /Applications/SWI-Prolog.app/Contents/swipl/pack/plosc/lib/x86_64-darwin14.3.0/plosc.dylib

Reason: image not found

Warning: /Applications/SWI-Prolog.app/Contents/swipl/pack/plosc/prolog/plosc.pl:36:

Goal (directive) failed: plosc:use_foreign_library(foreign(plosc))

ERROR: Exported procedure plosc:osc_mk_server/2 is not defined

ERROR: Exported procedure plosc:osc_now/2 is not defined

ERROR: Exported procedure plosc:osc_start_server/1 is not defined

ERROR: Exported procedure plosc:osc_stop_server/1 is not defined

ERROR: Exported procedure plosc:osc_run_server/1 is not defined

ERROR: Exported procedure plosc:osc_is_address/1 is not defined

ERROR: Exported procedure plosc:osc_mk_address/3 is not defined

ERROR: Exported procedure plosc:osc_split_address/3 is not defined

true.


Samer Abdallah

unread,
Aug 3, 2016, 3:36:12 PM8/3/16
to roberto morales, SWI-Prolog
Hi Roberto,

Thanks for trying plosc! The compilation warnings are not important,
but it’s interesting that it’s trying to load libswipl.dylib from
/Users/janw/stable/lib/swipl-7.2.3/lib/x86_64-darwin14.3.0/libswipl.dylib
This looks like a problem in the pack build system, so I would suggest upgrading
to a newer version of SWI.

BTW. I have some code for talking to Supercollider from Prolog using plsc - you may
prefer to have fun writing your own, but at some point we could put together
a Supercollider pack.

Best wishes,
Samer
> --
> You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Roberto Morales

unread,
Aug 3, 2016, 6:53:36 PM8/3/16
to Samer Abdallah, SWI-Prolog
Hi Samer

Thank you very much for your quick response!

I just downloaded Version 7.3.24 and got same error.
Any version that is working for you?

thanks in advance

ps

and yes, lets get some exchange, I was working in Prolog long tome ago a did many pieces with it.

Roberto Morales

unread,
Aug 3, 2016, 8:44:27 PM8/3/16
to Samer Abdallah, SWI-Prolog
Hi Samer

I delete the OSX version, and downloaded from mac ports version 7.2.3, it works!!!!

no gui interface which is in the dmg, but for me is just fine.

One last question: is it posible to have the sh emacs interacting with swi-prolog like the old days?

thanks in advance

great work Samer!!

Jan Wielemaker

unread,
Aug 4, 2016, 3:29:46 AM8/4/16
to Roberto Morales, Samer Abdallah, SWI-Prolog
On 08/04/2016 02:44 AM, Roberto Morales wrote:
> Hi Samer
>
> I delete the OSX version, and downloaded from mac ports version 7.2.3, it works!!!!

Yes, there is a dylib path problem when compiling extensions for the
packaged
binary. Never really bothered sorting that out. If someone with a Mac and
experience can figure it out ... It is either something with otool that
needs
to be done and/or adjusting swipl-ld to somehow pick up the right path and
compile it into the extension. The problem originates from the different
dylib dependencies in the app version.

> no gui interface which is in the dmg, but for me is just fine.
>
> One last question: is it posible to have the sh emacs interacting with swi-prolog like the old days?

Maybe :- set_prolog_flag(editor, emacs).? That said, if you want GNU-Emacs,
either run Prolog in the Emacs buffer using one of the modes or just run it
in another window and type ?- make. after editing.

Cheers --- Jan

Roberto Morales

unread,
Aug 7, 2016, 11:53:27 AM8/7/16
to Jan Wielemaker, Samer Abdallah, SWI-Prolog
Thank you very much fro all your feedback

Ok
currentlyI have emacs woking great, I am able to talk fluent to SuperCollider, according to Jan’s examples, back and forth, but
I can-t call prolog predicates from SuperCollider.
I don’t understand very clear what is happening

let me show you the code examples:

%Server sc - Client swpl


init1 :- osc_mk_address(localhost,57120, A),
assert(osc_addr_sc(A)).

bing1 :- osc_addr_sc(A),
get_time(T),
% osc_send(A,'/swpl',[string('[1,2,3,4]')],T).
osc_send(A,'/swpl',[string('Array.fill(5,{7.rand})')],T).


%==================

// ===== sc side

z = OSCFunc({|msg|
msg.postln;
~ea[1].asString.interpret
},'/swpl');

z.free

//============= and does exactly what is expected

But when I Try the other way around I can’t call any predicate

%Server swpl - Client sc


dumposc(P,A) :- writeln(msg(P,A)),
A=[string(Z)],
term_string(Term, Z),
format('~@', [Term]).



forward(P,[string(Host),int(Port),string(Msg)|Args]) :- osc_mk_address(Host,Port,Addr),
osc_send(Addr,Msg,Args).





:- osc_mk_server(7770,S),
osc_mk_address(localhost,7770,P),
osc_add_handler(S,'/notas',any,dumposc),
osc_add_handler(S,'/fwd',any,forward), assert(server(S,P)).


%===================

//=== para swi-prolog

n = NetAddr("127.0.0.1",7770 );

// this is one of my predicate

n.sendMsg("/notas","atasca([[60,64]],5)")

//=== pruebas
//=== which append/3

n.sendMsg("/notas","append([1],[2],X)")


%%%%%%%%

I just get the message report without executing the term

?- [sockets_re07sw].
Warning: /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/sockets_re07sw.pl:41:
Singleton variables: [P]
true.

?- start.
true.

OSC server started.
?- msg(/notas,[string(append([1],[2],X))])

%====================================


%% if I run this line separately from the server it works

A=[string(Z)], term_string(Term, Z), format('~@', [Term]).




thanks in advance

roberto

Samer Abdallah

unread,
Aug 12, 2016, 7:51:00 AM8/12/16
to Roberto Morales, SWI-Prolog
Hi Roberto,
Sorry for the delay in replying - I was reviving my Supercollider
stuff which I haven’t touched for a few years! I’d forgotten how
awful the Supercollider language is.

However, I think the problem here is nothing to do with the OSC
stuff. In your example, the body of dumposc/2 essentially reduces to

format('~@', [append([1], [2], [1, 2])]).

The ‘~@‘ format specifier expects to find a callable term in the argument
which _writes something to the output stream_. The written output is
captured and inserted in the formatted string. In this case, the append
goal is called and I suspect works perfectly, but it does not write any output.
Even though the ‘X’ in the term is bound to [1, 2], there is nothing
to print it. You could replace dumposc/2 with

> dumposc(P,A) :- writeln(msg(P,A)),
> A=[string(Z)],
> term_string(Term, Z),
format(‘Going to call: ~q’,[Term]),
call(Term),
format(‘After calling: ~q’,[Term]).

Of course, in a wider context this is EXTREMELY DANGEROUS as anyone on
your network can execute arbitrary Prolog code on your computer!

best wishes,
Samer
signature.asc

Roberto Morales

unread,
Aug 16, 2016, 10:46:15 AM8/16/16
to Samer Abdallah, SWI-Prolog
Hi Samer

I was travelling and until now got to my email, every thing works very well !!.
next day after my las email i realised why we had no feedback on the terminal (I still reviewing Prolog)
but now exactly what I want

Thanks again for your work in OSC

ps

Here is an example of what I am running back and forth sc - plosc

//===== sc =============

//=== for swi-prolog
n = NetAddr("127.0.0.1",7770 );

//== here I send a predicate to swi-prolog
(
j = "atasca("++[[50,64,58,60,48].scramble]++","++rrand(1,4)++")";

n.sendMsg("/notas",j)
)

// and here I listen to the sequence generated by prolog using Pbind
(
~spnotas = OSCFunc({|msg|
msg.postln;
~no = msg[1].asString.interpret
},'/swpl_note');

~spmet = OSCFunc({|msg|
msg.postln;
~me = msg[1].asString.interpret
},'/swpl_met');

~spdin = OSCFunc({|msg|
msg.postln;
~di = msg[1].asString.interpret;
Pbind(
\instrument, \help_oteypianostring,
\delat,1,
\degree, Pseq(~no -60),
\dur, Pseq(~me/1000),
\vol,Pseq(~di/127)).play
},'/swpl_din');
)

//========Post window

-> a NetAddr(127.0.0.1, 7770)
[ /datos, [fraces=[sujeto,predicado],tablas=[[1/h,4/i]]] ]
[ /datos, [1,1,1] ]
[ /datos, [4,4,4] ]
[ /datos, va la siguiente voz ...... ]
[ /swpl_note, [48,50,52,53,51] ]
[ /swpl_met, [4000,1500,250,250,2000] ]
[ /swpl_din, [58,75,65,70,58] ]



//===== swi-prolog =======


?- [f_0206_swp].
Warning: /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/sockets_re07sw.pl:39:
Singleton variables: [P]
Warning: /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/motivos_ad_re07gp.pl:130:
Singleton-marked variable appears more than once: _Z
Warning: /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/reyna_re07gp.pl:213:
Singleton variable in branch: Nota_1
Singleton variable in branch: Nota_f
Warning: /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/estados.pl:39:
Singleton-marked variable appears more than once: _X
Singleton-marked variable appears more than once: _Y
Singleton-marked variable appears more than once: _Z
Warning: /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/transas1.pl:3:
Redefined static procedure estados/1
Previously defined at /Users/rmm/dev/Swi_escamol/escamol_reloaded_SWI/estados.pl:10
true.

?- init1.
true.

?- start.
OSC server started.
true.

?- msg(/notas,[string(atasca([ [ 48, 50, 60, 58, 64 ] ],2))])

=================

and this how it works dumposc


dumposc(P,A) :- writeln(msg(P,A)),
A=[string(Z)],
term_string(Term, Z),
!,
call(Term).

I will try your suggestion . But so far this works very nice

Roberto Morales

unread,
Aug 30, 2016, 10:00:14 PM8/30/16
to Samer Abdallah, SWI-Prolog
Hi Samer

The prototype in OSX works fine and  now I am trying to port it to a raspberry pi 3.

Swi-prolog works great too and I am very exited in using this platform, although I am not very familiar with raspbian or Ubuntu

this is what I got now loading your plosc. I am sure is a very simple thing because is compiling correct but not putting the so file in its place and I sure you might have a solution for this.

I am skipping the warning which were the same as OSX

….

Warning:   ^
% make -C c
% make[1]: Entering directory '/home/pi/lib/swipl/pack/plosc/c'
% /usr/lib/swi-prolog/bin/armhf/swipl-ld -v -I/opt/local/include -L/opt/local/lib -llo -fPIC -Wall -shared -o plosc.so plosc.c
% eval `swipl --dump-runtime-variables`
% gcc -c -fPIC -Wall -fpic -fno-strict-aliasing -pthread -fPIC -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/ncursesw -D_REENTRANT -D__SWI_PROLOG__ -I/usr/lib/swi-prolog/include -I/opt/local/include -o plosc.o plosc.c
% gcc -o plosc.so -shared -rdynamic -Wl,-z,relro -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -pthread plosc.o -L/usr/lib/swi-prolog/lib/armhf -L/opt/local/lib -llo -lswipl
% rm plosc.o
% strip -x plosc.so
% make[1]: Leaving directory '/home/pi/lib/swipl/pack/plosc/c'
% echo "No checks defined."
% No checks defined.
% install: missing destination file operand after 'lib/armhf'
% Try 'install --help' for more information.
% make: *** [install] Error 1
% make -C c
% make[1]: Entering directory '/home/pi/lib/swipl/pack/plosc/c'
% make[1]: Nothing to be done for 'main'.
% make[1]: Leaving directory '/home/pi/lib/swipl/pack/plosc/c'
% install -d lib/armhf
% install -bCS c/plosc.so lib/armhf
% Makefile:18: recipe for target 'install' failed
ERROR: Process "process(path(make),[install])": exit status: 2



I notice that the building.sh had the SWISOLIB= ' ‘ empty so:

so I replace it with

...
PACKSODIR='lib/armhf'
SWISOLIB='-lswipl'
SWILIB='-lswipl'
….
But I could not make install successful outside prolog


thanks in advance again

roberto
Reply all
Reply to author
Forward
0 new messages