在 Obj-C 项目中嵌入 Prolog 引擎
我正在寻找一个轻量级的 Prolog 引擎,嵌入到 Mac OSX 下的 Obj-C 应用程序中。
在 Java 中,有一些优秀的实现具有我需要的特性:可部署性、轻便性、动态可配置性、与 Java 的集成以及易于互操作性。 你能推荐一些类似的 C/C++ 语言吗?
经过几次搜索后,我找到了 YAProlog 并阅读此处似乎它可以用作从其他程序调用的库。但是(愚蠢的问题):
- 我对 UNIX 缺乏经验,并且不知道如何使用 YAP 手册中的那些命令生成 libyap.a 文件...
- 然后我可以将 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):
- I'm inexperienced with UNIX and I don't know exactly how to produce libyap.a file with those commands of the YAP manual...
- Can I then copy libyap.a in my Xcode project and use it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GProlog
支持 Mac OS X (Darwin),并且有一个适用于 Mac 的安装程序OS X Leopard。 此处您可以阅读如何从 C 调用 gprolog (另请阅读 这个)。然后,您可以使用gcc
,而不是使用gplc
,前提是您添加了正确的链接选项,这可能会有点“棘手”;所以你可以使用 gplc 生成目标文件,然后将所有内容粘合在一起...关于 YAP:
1) 通常使用 autoconf 的包只需使用以下命令“序列”进行编译
最后的 make install 应该安装所有内容,并且必须由有权执行此操作的用户执行。该手册建议创建一个
ARCH
(ARCH.?) 目录并从那里执行所有操作(因此,../configure
而不是./configure)。
configure
脚本通常接受选项,看看它们。特别检查LIBDIR
和YAPLIBDIR
的位置。因此,一旦您获得了源代码 tarball(源代码的
.tar.gz
),您就应该对其进行解档,使用类似tar -xzf Yap-5.1.3.tar.gz< 的命令< /code> 适用于 GNU/Linux,相同的
tar
也应该适用于 Mac OS X...让我们看看
./configure --help
并看看您是否看到在继续之前您想要使用的有趣选项。现在,让我们按照手册的建议进行操作(即使它对我来说看起来很奇怪;-))
您等待...目录中将填充下一步所需的所有内容。看一下创建的
Makefile
,您会看到类似Within the Targets of the Makefile, I can read also
libYap.a
的行。所以,尝试make
(我不会这样做来检查可能出错的地方,也因为我使用的是 GNU/Linux,解决问题的方式可能会有所不同),最后,你应该获得libYap.a
,因此,成为“root”(管理员)并在
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 usinggplc
, you can usegcc
provided that you add the proper options for linking, which could be a bit "trickie" to be found; so you can produce object files withgplc
and then glue everything together...About YAP:
1) Usually package with autoconf are compiled simply with the following "sequence" of commands
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 anARCH
(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 areLIBDIR
andYAPLIBDIR
.So, once you have the source tarball (the
.tar.gz
of the source), you should dearchive it, a command liketar -xzf Yap-5.1.3.tar.gz
works on GNU/Linux and the sametar
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;-))
You wait... and the directory gets populated of evrything needed for the next step. Take a look at the created
Makefile
, you see lines likeAmong the targets of the Makefile, I can read also
libYap.a
. So, try themake
(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 thelibYap.a
, and so, become "root" (administrator) and doIn the
install
target (exactlyinstall_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.手册的 SWI-Prolog 的外语界面部分有一个条目 嵌入 SWI-Prolog在其他应用程序中。至于从 Objective C 调用它,应该和调用任何 C 代码一样容易。
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.