gpt4 book ai didi

c++ - PL_new_term_refs() : No foreign environment

转载 作者:太空宇宙 更新时间:2023-11-04 14:02:05 24 4
gpt4 key购买 nike

我正在尝试从 C++ 应用程序调用 SWI-Prolog。

我目前正在尝试运行官方文档中提供的一些代码:

#include <SWI-Prolog.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
term_t a0 = PL_new_term_refs(2);
static predicate_t p;

if ( !p )
p = PL_predicate("listing", 1, "database");

PL_put_atom_chars(a0, "member");
cout << PL_open_query(NULL, PL_Q_NORMAL, p, a0);
cout << a0;

return 0;
}

它编译正常,但是当我尝试运行它时,我收到这个错误:

[ fatal error :
PL_new_term_refs(): 无外来环境]

我可以知道这是什么问题吗?我在 Google 上找不到与该主题相关的任何内容。

非常感谢。

这是我遵循的文档:http://www.swi-prolog.org/pldoc/doc_for?object=section%283,%279.4.9%27,swi%28%27/doc/Manual/foreigninclude.html%27%29%29

最佳答案

我觉得你应该调用PL_initialise (argc, argv) 之前,但除此之外,看看 C++ interface .我最后在 pqConsole 中广泛使用了它项目,我必须说它确实比 C 接口(interface)简单

关于c++ - PL_new_term_refs() : No foreign environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18879932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com