# HG changeset patch # User samer # Date 1328785030 0 # Node ID 256016cddcbaa7af3dab2338855f688b1e920066 # Parent e0a1f92fcbc97774410b4f6ce56df36648cf7f53 Moved to library(debug) for messages; more helpful message if foreign library fails to load. diff -r e0a1f92fcbc9 -r 256016cddcba INSTALL --- a/INSTALL Mon Feb 06 14:25:05 2012 +0000 +++ b/INSTALL Thu Feb 09 10:57:10 2012 +0000 @@ -9,7 +9,7 @@ *** Centre for Computational Creativity *** Goldsmiths College, University of London *** -*** Dec 2004--January 2012 +*** 2004--2012 ------------------------------------------------------------------------- @@ -62,9 +62,18 @@ ------------------------------------------------------------------------- SANITY CHECK -If the installation is ok, then the following should work: +NB: you need to make sure the required Matlab dynamic libraries are +on your dyld search path before starting SWI Prolog. The bash script +swiplml shows how you can do this by setting the DYLD_FALLBACK_LIBRARY_PATH +environment variable before calling swipl, but be aware that there +are several environment variables that can affect dynamic library loading +and that they can have weird effects on your system if you have conflicting +libraries is different places. See the dyld man page ('man dyld'). - $ swipl +If the installation is ok, then the following should work (using the +included swiplml script): + + $ swiplml ?- use_module(library(plml)). ... Yes. @@ -77,4 +86,6 @@ ?- float(A)===2*pi. A = 6.28319 + ?- A:float===2*pi. + A = 6.28319 diff -r e0a1f92fcbc9 -r 256016cddcba README --- a/README Mon Feb 06 14:25:05 2012 +0000 +++ b/README Thu Feb 09 10:57:10 2012 +0000 @@ -9,13 +9,20 @@ *** Centre for Computational Creativity *** Goldsmiths College, University of London *** -*** Dec 2004--January 2012 +*** 2004--2012 ------------------------------------------------------------------------- NB: output type tagging system has changed but this documentation has not yet. See pldoc documentation of plml.pl. +Also: you need to make sure the required Matlab dynamic libraries are +on your dyld search path before starting SWI Prolog. The bash script +swiplml shows how you can do this by setting the DYLD_FALLBACK_LIBRARY_PATH +environment variable before calling swipl, but be aware that there +are several environment variables that can affect dynamic library loading +and that they can have weird effects on your system if you have conflicting +libraries is different places. See the dyld man page ('man dyld'). ------------------------------------------------------------------------- @@ -180,7 +187,7 @@ To help with debugging, you can issue the command: - ?- utils:set_state(debug,on). + ?- debug(plml). which will cause each Matlab expression to be printed in its Matlab form before execution. @@ -312,6 +319,10 @@ mutex is locked, it fails immediately without blocking. The blob is not reclaimed but will be can be reclaimed the next time gc is run. +2012-02-09 + Now using library(debug) for debugging messages. Added more helpful + message if foreign library fails to load. + ------------------------------------------------------------------------- ACKNOWLEDGMENTS diff -r e0a1f92fcbc9 -r 256016cddcba cpp/Makefile --- a/cpp/Makefile Mon Feb 06 14:25:05 2012 +0000 +++ b/cpp/Makefile Thu Feb 09 10:57:10 2012 +0000 @@ -4,7 +4,7 @@ TARGET=plml.$(SO) INCML=$(MATLAB)/extern/include LIBML=$(MATLAB)/bin/$(MLARCH) -PLLDFLAGS=$(CXX) $(INCLUDES) -I$(INCML) -Wall -g3 +PLLDFLAGS=$(CXX) $(INCLUDES) -I$(INCML) -Wall .SUFFIXES: .cpp .o .so .dylib @@ -24,4 +24,5 @@ install: install -d $(INSTALL_LIB_TO) install $(INSTALL_FLAGS) $(TARGET) $(INSTALL_LIB_TO) + install $(INSTALL_FLAGS) logio $(INSTALL_LIB_TO) diff -r e0a1f92fcbc9 -r 256016cddcba prolog/plml.pl --- a/prolog/plml.pl Mon Feb 06 14:25:05 2012 +0000 +++ b/prolog/plml.pl Thu Feb 09 10:57:10 2012 +0000 @@ -221,8 +221,6 @@ :- use_module(library(dcgu)). :- use_module(library(ops)). -:- load_foreign_library(foreign(plml)). - :- op(700,xfx,===). % variable binding/assignment in matlab query :- op(951,fx,??). % evaluate term as matlab :- op(951,fx,???). % evaluate term as matlab boolean @@ -238,17 +236,28 @@ :- dynamic plml_flag/2. +load_plml :- + catch( load_foreign_library(foreign(plml)), + Ex, ( + writeln('\n** Failed to load plml dynamic library. Possible causes:'), + writeln(' (1) plml.dylib or plml.so is not on foreign(_) search path (see file_search_path/2).'), + writeln(' (2) Matlab libraries not on dyld library path (need to set DYLD_FALLBACK_LIBRARY_PATH).'), + writeln(' Check error message below for more information.\n'), + throw(Ex) + )). + set_flag(Flag,Value) :- ground(Flag), retractall(plml_flag(Flag,_)), assert(plml_flag(Flag,Value)). + +ml_closeall :- + forall(plml_flag(ml(Id),open), ml_close(Id)). + +:- load_plml. :- at_halt(ml_closeall). -ml_closeall :- - forall(plml_flag(ml(Id),open), - ( format('Closing Matlab engine (~w)...',[Id]), - ml_close(Id))). %% matlab_init( -Key, -Cmd:ml_expr) is nondet. % Each user-defined clause of matlab_init/2 causes Cmd to be executed @@ -298,10 +307,15 @@ ; Exec='ssh /usr/local/bin/matlab' ), ( member(debug(In,Out),Options) - -> format(atom(Exec1),'stdio_catcher ~w ~w ~w',[In,Out,Exec]) + -> debug(plml,'Running Matlab with protocol logging.',[]), + debug(plml,'| Prolog > Matlab logged to "~w"',[In]), + debug(plml,'| Prolog < Matlab logged to "~w"',[Out]), + absolute_file_name(foreign(logio),Spy,[access(read)]), + format(atom(Exec1),'~w ~w ~w ~w',[Spy,In,Out,Exec]) ; Exec1=Exec ), format(atom(Cmd),'~w ~w',[Exec1,Flags]), + debug(plml,'About to start Matlab with: ~w\n',[Cmd]), mlOPEN(Cmd,Id), set_flag(ml(Id),open), ( member(noinit,Options) -> true @@ -327,6 +341,7 @@ % Execute Matlab expression without returning any values. ml_exec(Id,X) :- term_mlstring(Id,X,C), !, + debug(plml,'plml:ml_exec>> ~s\n',[C]), mlEXEC(Id,C). %% ml_eval(+Id:ml_eng, +Expr:ml_expr, +Types:list(type), -Res:list(ml_val)) is det.