在 Obj-C 项目中嵌入 Prolog 引擎

发布于 2024-09-09 05:39:06 字数 432 浏览 3 评论 0原文

我正在寻找一个轻量级的 Prolog 引擎,嵌入到 Mac OSX 下的 Obj-C 应用程序中。
在 Java 中,有一些优秀的实现具有我需要的特性:可部署性、轻便性、动态可配置性、与 Java 的集成以及易于互操作性。 你能推荐一些类似的 C/C++ 语言吗?


经过几次搜索后,我找到了 YAProlog 并阅读此处似乎它可以用作从其他程序调用的库。但是(愚蠢的问题):

  1. 我对 UNIX 缺乏经验,并且不知道如何使用 YAP 手册中的那些命令生成 libyap.a 文件...
  2. 然后我可以将 libyap.a 复制到我的 Xcode 项目中并使用它吗?

I'm looking for a light-weight Prolog engine to be embedded in an Obj-C application under Mac OSX.
In Java there are some excellent implementations with the characteristics I need: deployability, lightness, dynamic configurability, integration with Java and ease of interoperability.
Can you recommend something similar in C/C++?


After several searches I found YAProlog and reading here it seems it can be used as library to be called from other programs. But (stupid questions):

  1. I'm inexperienced with UNIX and I don't know exactly how to produce libyap.a file with those commands of the YAP manual...
  2. Can I then copy libyap.a in my Xcode project and use it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空名 2024-09-16 05:39:06

GProlog 支持 Mac OS X (Darwin),并且有一个适用于 Mac 的安装程序OS X Leopard。 此处您可以阅读如何从 C 调用 gprolog (另请阅读 这个)。然后,您可以使用 gcc,而不是使用 gplc,前提是您添加了正确的链接选项,这可能会有点“棘手”;所以你可以使用 gplc 生成目标文件,然后将所有内容粘合在一起...

关于 YAP:

1) 通常使用 autoconf 的包只需使用以下命令“序列”进行编译

./configure
make

最后的 make install 应该安装所有内容,并且必须由有权执行此操作的用户执行。该手册建议创建一个 ARCH (ARCH.?) 目录并从那里执行所有操作(因此,../configure 而不是 ./configure)。

configure 脚本通常接受选项,看看它们。特别检查 LIBDIRYAPLIBDIR 的位置。

因此,一旦您获得了源代码 tarball(源代码的 .tar.gz),您就应该对其进行解档,使用类似 tar -xzf Yap-5.1.3.tar.gz< 的命令< /code> 适用于 GNU/Linux,相同的 tar 也应该适用于 Mac OS X...

让我们看看 ./configure --help 并看看您是否看到在继续之前您想要使用的有趣选项。

现在,让我们按照手册的建议进行操作(即使它对我来说看起来很奇怪;-))

mkdir ARCH.  # I would put GNUlinux, or maybe
             # the name must be exactly this?
cd ARCH.
../configure

您等待...目录中将填充下一步所需的所有内容。看一下创建的 Makefile,您会看到类似

#
# where YAP should look for binary libraries
#
LIBDIR=$(EROOTDIR)/lib
YAPLIBDIR=$(EROOTDIR)/lib/Yap

Within the Targets of the Makefile, I can read also libYap.a 的行。所以,尝试 make (我不会这样做来检查可能出错的地方,也因为我使用的是 GNU/Linux,解决问题的方式可能会有所不同),最后,你应该获得libYap.a,因此,成为“root”(管理员)并

make install

install目标中执行(对我来说正是install_unix)我读到 $(INSTALL_DATA) -m 755 libYap.a $(DESTDIR)$(LIBDIR) 这意味着您的 .a 已安装并且应该可供使用一个编译器,前提是您知道库在哪里(并且您知道它,请参见上面并记住配置的选项)

2)当然您可以直接将其复制到您需要的地方并“直接”使用它,但因为它是“规范的” ”由 make install 安装,使用它的方式与使用任何其他“系统范围”lib 存档一样。

GProlog supports Mac OS X (Darwin) and there's an installer for Mac OS X Leopard. And here you can read how to call gprolog from C (read also this). Then instead of using gplc, you can use gcc provided that you add the proper options for linking, which could be a bit "trickie" to be found; so you can produce object files with gplc and then glue everything together...

About YAP:

1) Usually package with autoconf are compiled simply with the following "sequence" of commands

./configure
make

A final make install should install everything and must be executed by a user having the rights to do so. The manual suggest the creation of an ARCH (ARCH.?) dir and doing everything from there (so, ../configure instead of ./configure).

The configure script accepts usually options, take a look at them. Check in particular where are LIBDIR and YAPLIBDIR.

So, once you have the source tarball (the .tar.gz of the source), you should dearchive it, a command like tar -xzf Yap-5.1.3.tar.gz works on GNU/Linux and the same tar should be also on Mac OS X...

Let's look at ./configure --help and look if you see interesting option you want to use before proceeding.

Now, let's follow manual's suggestion (even if it looks odd to me;-))

mkdir ARCH.  # I would put GNUlinux, or maybe
             # the name must be exactly this?
cd ARCH.
../configure

You wait... and the directory gets populated of evrything needed for the next step. Take a look at the created Makefile, you see lines like

#
# where YAP should look for binary libraries
#
LIBDIR=$(EROOTDIR)/lib
YAPLIBDIR=$(EROOTDIR)/lib/Yap

Among the targets of the Makefile, I can read also libYap.a. So, try the make (I won't do that to check what can go wrong, also because I am on GNU/Linux and how I can solve problems could be different), at the end, you should obtain the libYap.a, and so, become "root" (administrator) and do

make install

In the install target (exactly install_unix for me) I read $(INSTALL_DATA) -m 755 libYap.a $(DESTDIR)$(LIBDIR) which means that your .a is installed and should be ready to be used by a compiler, provided you know where the lib is (and you know it, see above and remember the configure's options)

2) Of course you can copy it directly where you need it and use it "directly", but since it is "canonically" installed by the make install, use it the way you'd use any other "system wide" lib archive.

栖迟 2024-09-16 05:39:06

手册的 SWI-Prolog 的外语界面部分有一个条目 嵌入 SWI-Prolog在其他应用程序中。至于从 Objective C 调用它,应该和调用任何 C 代码一样容易。

12.4.23 在其他应用程序中嵌入 SWI-Prolog

对于嵌入式 Prolog,我们指的是“主”程序不是 Prolog 应用程序的情况。 Prolog 有时嵌入到 C、C++、Java 或其他语言中,以便在较大的应用程序中提供基于逻辑的服务。嵌入将 Prolog 引擎作为库加载到外部语言。 Prolog本身只提供C语言的嵌入(与C++兼容)。 Java 中的嵌入是通过使用 Java 和 Prolog C 接口之间的 C 粘合剂 JPL 来实现的。

SWI-Prolog’s Foreign Language Interface section of the manual has an entry for Embedding SWI-Prolog in other applications. As far as calling it from Objective C, it should be possible just as easily as calling any C code.

12.4.23 Embedding SWI-Prolog in other applications

With embedded Prolog we refer to the situation where the‘main' program is not the Prolog application. Prolog is sometimes embedded in C, C++, Java or other languages to provide logic based services in a larger application. Embedding loads the Prolog engine as a library to the external language. Prolog itself only provides for embedding in the C language (compatible with C++). Embedding in Java is achieved using JPL using a C-glue between the Java and Prolog C interfaces.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文