如何将C ++与prolog集成? [英] How can I integrate C++ with prolog?

查看:97
本文介绍了如何将C ++与prolog集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Embarcadero Rad Studio通过c ++访问Prolog,这意味着我想从C ++中获取输入并在prolog中处理输入并再次在C ++中显示输出。但它给出了无法链接错误..

我得到了这个想法并编写了引用链接https://www.youtube.com/watch?v=e-cHzbJMQ9k的程序使用QTCreator在C ++中编写程序..

它给出了以下错误列表: -



I want to access Prolog through c++ using Embarcadero Rad Studio, means I want to take input from C++ and get the input processed in prolog and again display the output in C++. But it is giving an "unable to link error"..
I got the idea and coded the program referencing the link "https://www.youtube.com/watch?v=e-cHzbJMQ9k" in which the program was coded in C++ using QTCreator ..
It gives the following List of errors :-

[ILINK32 Error] Error: Unresolved external '_PL_cut_query' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_new_term_ref' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_exception' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_fatal_error' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_chars_to_term' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_put_term' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_predicate' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_open_query' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_next_solution' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_get_arg' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_get_name_arity' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unresolved external '_PL_atom_chars' referenced from C:\USERS\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\PROLOGS.OBJ
[ILINK32 Error] Error: Unable to perform link





我尝试了什么:





What I have tried:

#include <iostream>
#include <sstream>
#include "SWI-cpp.h"
#include "SWI-Prolog.h"
#include "SWI-Stream.h"
#include <conio.h>

using namespace std;

term_t a;
term_t b;
term_t ans;
functor_t fun;

int main()
{
  int digit;
  cout << "\nPlease enter a digit to calculate it's Factorial.." << endl;
  cin >> digit;
  PlCall("consult(C:\Program Files(x86)\swipl\bin('swipl-win.rc'))");
  PlCall("consult('factorial.pl')");//'factorial.pl')");
  a = PL_new_term_ref();
  PL_put_integer(a, digit);
  b   = PL_new_term_ref();
  ans = PL_new_term_ref();
  fun = PL_new_functor(PL_new_atom("factorial"),2);
  PL_cons_functor(ans, fun, a, b);
  int fact;
  if(PL_call(ans, NULL)) {
	PL_get_integer(b, &fact);
	//int numb = fact;
  }                   
	return 0;
}

推荐答案

谢谢大家的建议。

我得到了解决方案将SWI-Prolog图书馆与Embarcadero Rad Studio联系起来。



解决方案: -



1 )。我在命令提示符下使用 implib.exe 将SWI-Prolog库libswipl.dll转换为coff格式库,因为库是omf格式和所需格式是coff。



2)。在获得SWI-prolog库的coff格式后,我将其复制到Embarcadero的项目文件夹并将其包含在项目中。



此包含解决了链接错误并执行了项目。



感谢大家的建议..
Thank you all for your suggestions.
I got the solution to link the library of SWI-Prolog with Embarcadero Rad Studio.

Solution :-

1). I used the implib.exe in command prompt to convert the SWI-Prolog library "libswipl.dll" to get the "coff" format library as the library was in the "omf" format and the required format was "coff".

2). After getting the "coff" format of library of SWI-prolog, I copied it to the Embarcadero's Project Folder and included it in the Project.

This inclusion resolved the linking error and executed the Project.

Thank you to all for your suggestions..


您可能错过了连接库的地方PL_xxx函数已定义。

在项目设置中指定库名称和路径。



如果您使用的是Visual Studio,可在此处指定 -

You may have missed linking the library where the PL_xxx functions are defined.
Specify the library name and path in the project settings.

If you're using Visual Studio, you can specify it here -
Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies<br />


这篇关于如何将C ++与prolog集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆