Hi John,
mcculloch wrote:
- Can foreign C predicates be in a library file or do they have to be
compiled by ciaoc along with the prolog code?
In ciao, foreign C predicates can be in a library file. See for example, the Mathematical functions example in the documentation of the foreign interface. http://ciao-lang.org/docs/ciao/foreign_interface_doc.html
- Has anyone successfully used C++ for foreign code with ciao and what did
they do to make it work?
Yes. In fact the high level C interface have been developed for (but not only) interfacing ciao with the Parma Polyhedra Library (ppl) a constraint library written in C++.
Unfortunately, ppl is pretty difficult to link with ciao because of some sensitive dependencies between gmp, ppl, ciao, the target architecture, and the compiler that compile/link everything.
Nonetheless ppl is maybe not the better example for you because it is built on the top of a common interface for different Prologs (Ciao, GNU, SICStus, SWI, XSB, YAP). This common interface uses therefore complex abstraction for the way the different systems interface with C/C++.
The simplest idea to interface Ciao and C++ would be to write C functions (functions prefixed by 'extern "C"' in the C++ code) that wrap calls from prolog to C++. Then C++ object could be casted as addresses.
I just included in the documentation of the foreign interface an example of the interface with C++ . But because Ciao web site is currently not generated, I join the example here. Note that to be able to run, the example needs a 32bits version of GNU Standard C++ Library (which is not always installed by default on 64 bits Linux).
Cheers,
Remy