Distributable SWI Prolog distribution for Mac OS

For Mac OS users several options are available for installing SWI Prolog: manual compilation, using the homebrew package and using the DMG.

However, as far as I can see, there are no ready available binaries already compiled. I’m looking for a way to easily package an application using SWI Prolog. Therefore I want to include a version of SWI Prolog inside my own application and make some kind of wrapper for it to run my application. Any tips on how to achieve this? I tried copying the installed DMG contents to a directory, but this won’t get my packs for some reason.

I think using the DMG is the right start as it is self contained and designed to be relocatable.

You can use attach_packs/2 to define a base directory below it will search for packs. That is also used by e.g. SWISH to deal with packages bundled with the application.

1 Like

Thanks for the answer Jan!

However, even with attach_packs, packs are not properly picked up. The weird thing is that the homebrew version of SWI Prolog works fine.

To reproduce:

  1. Install SWI Prolog from DMG
  2. Clone terminusdb
  3. Install terminus_store_prolog
  4. Run TerminusDB (start.pl) from the DMG version of SWI Prolog.

Can you be a little more specific? This gets a lot of guess to what exactly you did where … Preferably some stuff I can just copy/paste (you can send a private message if that is more appropriate).

Okay, maybe I found the issue. I compiled the pack with the homebrew version of SWI Prolog by doing the following:

brew install swi-prolog
brew install rust
swipl
?- pack_install(terminus_store_prolog).

After it is installed, I tried to run the DMG version and it can’t find the pack at all. Even when manually inserting the pack directory. When I run the DMG version and try to load the module, I get:

?- use_module(library(terminus_store)).
ERROR: Exported procedure terminus_store:nb_set_head/2 is not defined
ERROR: Exported procedure terminus_store:layer_total_addition_count/2 is not defined
ERROR: Exported procedure terminus_store:open_directory_store/2 is not defined
ERROR: Exported procedure terminus_store:parent/2 is not defined
ERROR: Exported procedure terminus_store:id_triple_addition/4 is not defined
ERROR: Exported procedure terminus_store:id_triple_removal/4 is not defined
ERROR: Exported procedure terminus_store:node_and_value_count/2 is not defined
ERROR: Exported procedure terminus_store:store_id_layer/3 is not defined
ERROR: Exported procedure terminus_store:head/2 is not defined
ERROR: Exported procedure terminus_store:layer_total_removal_count/2 is not defined
ERROR: Exported procedure terminus_store:open_memory_store/1 is not defined
ERROR: Exported procedure terminus_store:squash/2 is not defined
ERROR: Exported procedure terminus_store:nb_apply_delta/2 is not defined
ERROR: Exported procedure terminus_store:pack_export/3 is not defined
ERROR: Exported procedure terminus_store:layer_total_triple_count/2 is not defined
ERROR: Exported procedure terminus_store:open_named_graph/3 is not defined
ERROR: Exported procedure terminus_store:layer_addition_count/2 is not defined
ERROR: Exported procedure terminus_store:builder_committed/1 is not defined
ERROR: Exported procedure terminus_store:pack_layerids_and_parents/2 is not defined
ERROR: Exported procedure terminus_store:open_write/2 is not defined
ERROR: Exported procedure terminus_store:layer_to_id/2 is not defined
ERROR: Exported procedure terminus_store:create_named_graph/3 is not defined
ERROR: Exported procedure terminus_store:layer_removal_count/2 is not defined
ERROR: Exported procedure terminus_store:id_triple/4 is not defined
ERROR: Exported procedure terminus_store:predicate_count/2 is not defined
ERROR: Exported procedure terminus_store:nb_commit/2 is not defined
ERROR: Exported procedure terminus_store:pack_import/3 is not defined
ERROR: Exported procedure terminus_store:nb_force_set_head/2 is not defined
true.

Installing the pack with pack_install on the DMG version does not work as well, and fails with:

% ld: library not found for -lswipl
ERROR: clang: error: linker command failed with exit code 1 (use -v to see invocation)

The fact that the below seems to work suggests it can find the pack, no? Surely the native code will not work as MacOS .dylibs have explicit paths to their dependencies, which point at the Homebrew installation. You can use otool to fix the library references. Have a look at some of the bundled foreign libraries to get the right paths.

If you use swipl-ld, this is a known issue. Configuring the required link command manually should work. You still need to properly place the plugin and edit its dependency paths using otool. The whole thing is quite complicated on the Mac :frowning:

1 Like

Thanks so much! I’m still a Mac OS noobie (running it for the first time in my life on a VM now for development), so I did not expect this kind of stuff. Will try your solution by using otool.