Generating Logtalk executables using gprolog

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
michael_wernicki
Posts: 1
Joined: Mon Apr 14, 2014 9:51 pm

Generating Logtalk executables using gprolog

Post by michael_wernicki » Tue Apr 15, 2014 1:45 am

On the github wiki: https://github.com/LogtalkDotOrg/logtal ... ng-Logtalk there is an example of how to generate executables.


As follows:

Embedding Logtalk

The Logtalk 3 compiler and runtime are implemented using both Prolog and Logtalk source files. When embedding Logtalk, usually to generate a new Prolog top level or an executable that includes it, we first need to save the intermediate Prolog files generated by the compilation of the Logtalk source files. After starting Logtalk using your favorite backend Prolog compiler, type the query:

| ?- logtalk_compile([
core(expanding),
core(monitoring),
core(forwarding),
core(user),
core(logtalk),
core(core_messages)],
[scratch_directory('$HOME/collect')]).

Assuming, for example, that you're using a POSIX system and GNU Prolog as the backend compiler, we need to copy the adapter and default paths files to the directory where we're collecting all the files ($HOME/collect in our example):

$ cp $LOGTALKHOME/adapters/gnu.pl $HOME/collect/gnu.pl
$ cp $LOGTALKHOME/paths/paths.pl $HOME/collect/paths.pl
$ cp $LOGTALKHOME/core/core.pl $HOME/collect/core.pl

Now that we have all the necessary files in one place, its a good idea to take a look to the files in the integration directory for the chosen backend Prolog compiler and check if some changes to the core files are advised. For example, in the case of GNU Prolog, we can edit the $HOME/collect/core.pl file and add the line :- built_in. to the top to give all the predicates implementing the Logtalk compiler and runtime built-in status. After this step, the details to embed the collected Prolog files that implement Logtalk depend on the backend Prolog compiler. Continuing to use GNU Prolog for our tutorial, we can generate a new top-level executable file by typing:

$ cd $HOME/collect
$ gplc -o logtalk gnu.pl paths.pl expanding.pl monitoring.pl forwarding.pl user.pl logtalk.pl core_messages.pl core.pl

The created logtalk executable can now be moved to a suitable place or distributed to its users. Note that the executable will still look by default for a settings.lgt file in the startup directory and in the $LOGTALKUSER directory. If necessary, you can turn off loading of settings files by editing the adapter file and changing the value of the settings_file read-only flag to deny (Logtalk 3.00.0 Alpha 22 or later version required).


When I try the above, the following errors are generated:

~/collect $ gplc -o logtalk gnu.pl paths.pl expanding.pl monitoring.pl forwarding.pl user.pl logtalk.pl core_messages.pl core.pl
gnu.pl:702-704: warning: suspicious predicate {}/1
gnu.pl:705-707: warning: suspicious predicate {}/1
gnu.pl:710-713: warning: suspicious predicate {}/1
gnu.pl:714-715: warning: suspicious predicate {}/1
/tmp/gplcUHjhSQ.o: In function `Lpred24_19':
(.text+0x4412): undefined reference to `predicate(logtalk_library_path/2)'
/tmp/gplcv0MS42.o: In function `predicate('$lgt_create_mutexes'/1)':
(.text+0xdb08c): undefined reference to `predicate(mutex_property/2)'
collect2: error: ld returned 1 exit status
compilation failed

This occurs with logtalk-3.00.0-b1 or logtalk-3.00.0-a36 with the settings_file set to deny or allow.

The gprolog-1.4.4 is being used.

The default settings.lgt is being used and the paths.pl has not been modified. I'm looking to see whether something needs to be done in the paths.pl file.

Being able to generate stand-alone executables using gprolog and logtalk make the combination of the two very attractive. What version of logtalk worked with the example? What would be the easiest fix?

Mike

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Generating Logtalk executables using gprolog

Post by Paulo Moura » Tue Apr 15, 2014 2:43 am

Hi Mike,

The "suspicious predicate" warnings can be safely ignored for the {}/1 predicate. You can turn off this warning by using the gplc command-line option "--no-susp-warn". I just fixed the "undefined reference to `predicate(mutex_property/2)'" error in the Logtalk 3 git repository. The other error, "undefined reference to `predicate(logtalk_library_path/2)'", is puzzling, however, as the logtalk_library_path/2 predicate is declared and defined in the "paths.pl" file. I will look into it tomorrow. Thanks for the bug report.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Generating Logtalk executables using gprolog

Post by Paulo Moura » Tue Apr 15, 2014 11:33 am

I just tested and committed to the Logtalk 3 git repository a workaround to an apparent "gplc" bug with multifile predicates when generating executables that embed Logtalk using GNU Prolog:

https://github.com/LogtalkDotOrg/logtal ... af9870e0bd

I also mailed Daniel about this bug and I'm waiting for his reply. The problem didn't exist when I wrote the instructions on the wiki as the multifile predicate was not called at that time in the "core/logtalk.lgt" file.

Thanks again for your bug report.
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest