Re: Foreign interface
Grzegorz Jaśkiewicz <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CABWt2Wm4ikdzpGC=d=mijUYs9h6w5S6QX+w1LZvRPz_vTV7q3g@mail.gmail.com> |
i'm guessing the library you are trying to load is missing "install_mylib"
function (see. section 9.2.3 in
http://www.swi-prolog.org/pldoc/man?section=foreignlink).
To use shared libary in swi-prolog it must be created in proper way;
predicated must be exported to "call" any functions.
My suggestion would be to create a wrapper in C++ which loads your library
and serializes/deserializes terms back and forth between prolog interpreter
and the shared library.
So C++ code would look like something:
#include <windows.h>
#include <SWI-Prolog.h>
static foreign_t pl_say_hello(term_t to)
{
// convert term to something understandable by DLL function
// call DLL function with parameters
// unify results to get output
}
install_t install_mylib()
{
// load DLL library here
PL_register_foreign("say_hello", 1, pl_say_hello, 0);
}
and now you can do:
:- say_hello('hello world')
HTH
2013/8/13 bishoksan kafle <[email protected]>
> Hi,
> I have .dyld (may be .dll/.so) shared library. I could like to invoke
> some function in this library from swi-prolog, can you please brief me on
> how can I do this?
>
> In the swi-prolog webpage it comes with an example, but I could not really
> follow it. I do not have any source file and I can not understand where can
> I put install sth.?
>
> In my case, I am trying to make an interface with SMT solver z3, suppose
> that I only have .dyld (shared library). The command to run for this is z3.
>
> I tried this: :- use_foreign_library('/usr/local/lib/libz3', z3).
>
> I get the following message back:
> No install function in '/usr/local/lib/libz3.dylib'
> Tried: [z3]
> Warning: /Users/kafle/Desktop/z3-ciao/swi.pl:2:
> Goal (directive) failed: user:use_foreign_library(/usr/local/lib/libz3,z3)
>
> can you please show me how this could be achieved (consider that there is a
> function called "say_hello" inside this shared lib, how do I invoke it)?
>
>
> Many thanks in advance
> bishoksan
>
> --
> The race is not always won by the fastest runner, but sometimes by those
> who just keep running.
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed