Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C++
#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;
}
Posted
Updated 16-Mar-16 18:10pm
v4
Comments
Sergey Alexandrovich Kryukov 10-Mar-16 22:07pm    
It depends on... which Prolog?
—SA
R2G 11-Mar-16 0:46am    
on SWI-Prolog..

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..
 
Share this answer
 
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 />
 
Share this answer
 
Comments
R2G 11-Mar-16 4:07am    
But I am using Embarcadero Rad Studio for c++ and SWI-Prolog for Prolog and I also cannot find out how to link the library in Embarcadero as I know the path and name of the library. Can you please help me out of this ??
«_Superman_» 11-Mar-16 4:16am    
Unfortunately, I'm not familiar with RAD Studio.
You could check its project properties for any option where you can specify the library name.
Or you could check if the pragma works by giving this in some header file - #pragma comment(lib, "lib name")
Use the library path in place of lib name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900