Integrating Prolog with C#

Integrating Prolog with C#

The link you've provided has full explanation of this error:

If libswipl.dll or one of its dependencies could not found you will recive an error like
System.IO.FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)

An other common error is:

SWI-Prolog: [FATAL ERROR:
Could not find system resources]`
Failed to release stacks

To fix this add the SWI_HOME_DIR environment variable as described in SWI-Prolog FAQ FindResources with a statment like this befor calling PlEngine.Initialize.

Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc");

This code is commented by default, Uncomment it and provide the correct path to the the_PATH_to_boot32.prc. As described in FAQ:

Solution

On Windows, it suffices to leave libswipl.dll in the installation tree (i.e., do not copy it elsewhere) and add the bin directory of the installation tree to %PATH%.

A cross-platform and robust solution is to use putenv() to put an appropriate path into the environment before calling PL_initialise().

...;
putenv("SWI_HOME_DIR=C:\\Program Files\\swipl");
if ( PL_initialise(argc, argv) )
PL_halt(1);
...

In the final version of your application you link the saved-state to the executable (using swipl-ld or cat (Unix)) and comment the putenv() call.

Use Prolog with C# (Unity)

From the link you provided, is not apparent that the source is available here.
Just try to compile it, to fit your target machine architecture.

I'm trying to generate the interface on Linux, with MonoDevelop, but it's not immediate, will retry later. Meanwhile, you could try on Windows. Probably will be simpler...

edit

Now I had the time to attempt to compile from source in Windows 10 64 bits, and so far it seems to run pretty well. I'm using VisualStudio Community 2017, and after opened the solution (contrib-swiplcs\SwiPlCs_git.sln), have defined _PL_X64 in SwiPLcs properties - compilation.

HTH

edit

Have uploaded this repo that shows a simplified usage of SWIPlCs.
Note there is a directory (swipl_cs) where I have simply copied (unchanged) the indispensable source files from SwiPlCs.
There is a single Prolog file, that computes N-Queens problem solutions (just the first, to keep things as simple as possible) and displays the steps performed by CLP(FD) - thanks to Markus Triska for the original implementation.

Integration of C# and prolog

You can use for example: Prolog.NET or P# or A COM Wrapper

Integrating C# and Prolog

Perhaps you are having problems with 32 bit SWI-Prolog on 64 bit Windows. If your platform target is Any CPU it might be the cause of your problems. You can fix this by opening the properties pages for you C# project. Select the Build tab and change the Platform target to x86.

If you currently are using Any CPU your application will run in 64 bit on 64 bit Windows. Trying to load an 32 bit DLL will fail miserably.

Integrating prolog into other environments

I don't see any true requirement for a foreign language interface for your task: use Prolog IO, it's easy to use and efficient. You could also start with just support from protocol/1. Just a KISS advice...

A foreign language interface it's mandatory when you need something implemented in that other language.

SWI-Prolog C++ interface it's much easier to use than C counterpart, and allows both extending the language with really easy builtins' coding as well as embedding the engine in a standalone 'main'. And these 2 aspects can cohexist gracefully: say for a fast prototype just we implement the builtins, and use the REPL top level, while a full blown application can start the engine to be used as logic engine, and submit the (hopefully tested via REPL) queries in background.

Then there is JPL to interface SWI-Prolog and Java. I know little about it... I've seen some problem reported on the SWI-Prolog mailing list, due (mainly) to the complexity of different threading models. But certainly it's working.

An interesting development is occurring to make available the IDE into Eclipse (PDT, Prolog Development tools). I think they use their own Java interface. Currently could be a better choice than JPL.

But the most interesting interface SWI-Prolog can propose today it's the HTTP server infrastructure. If you known WEB client development (HTML/JavaScript/XML/RDF) you have plenty of tools to split your design in MVC Client/Server. Prolog runs a Web Service, and a Rich Client interacts with end user. This architecture make your application ready to run locally as well in the wild.

Please see the relevant How To section...Is not a simple task, but (IMHO) a very rewarding and long standing one.



Related Topics



Leave a reply



Submit