Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoiding plld in VS2008

Status
Not open for further replies.

HJoshy

Programmer
Mar 9, 2010
9
GB
Hello,

I have a large Prolog program with lots of predicates. I need to connect to this Prolog code from C++ (VS2008) to obtain certain query results.

So I am NOT trying to embed Prolog in C++ as a logical engine, but for my C++ program to connect to my Prolog code and obtain query results.

How can I avoid using the following command at the VS2008 Command Prompt?

plld -o myprog.exe mycpp.cpp mypl.pl

I mean is there any way I can get my VS2008 C++ program to consult my Prolog program without using the plld.exe utility program?

It is sometimes suggested that if one is using VS2008, they might be better off not using plld, by perhaps using a dll instead. Can someone please elaborate on this?

Thanks,
 
Sorry but I don't really understand your problem.

plld -dll -o myprog.exe mycpp.cpp mypl.pl produce a dll you can use in a C++ program.

you can also use socket to communicate with Prolog.
 

Thanks for the reply Joel.

What I mean is that how can I consult (compile) my Prolog program from within VS2008 C++ code without having to use plld.exe?

Normally, when I write a C++ program to call Prolog and vice versa, and I press F5 to build and compile it, my Prolog code doesn't get compiled as well. I can test this by typing listing at the prompt.

However, when I use:

plld -o prog.exe prog1.cpp prog2.pl

my Prolog program is "linked" to my VS2008 code, and therefore I can test and see the contents of my Prolog program by using listing.

But because plld is not quite compatible with some of the features I use in my VS2008 (robotics libraries, etc...), I am wondering how I can link these two without having to use the plld.exe utility program.

Is it any clear now what I am concerned with?

Cheers,

 

Here is my code in its entirety; in response to my own posting (Avoiding plld in VS2008).

Trying "listing." at the Prolog prompt that pops up when I run the program confirms that my Prolog source code has been loaded (consulted).

#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdafx.h>
using namespace std;
#include "Windows.h"
#include "ctype.h"
#include "SWI-cpp.h"
#include "SWI-Prolog.h"
#include "SWI-Stream.h"

int main(int argc, char** argv)
{
argc = 4;

argv[0] = "libpl.dll";
argv[1] = "-G32m";
argv[2] = "-L32m";
argv[3] = "-T32m";

PL_initialise(argc, argv);

if ( !PL_initialise(argc, argv) )
PL_halt(1);

PlCall( "consult(swi('plwin.rc'))" );
PlCall( "consult('hello.pl')" );

PL_halt( PL_toplevel() ? 0 : 1 );
}

So this is how to load a Prolog source code (hello.pl) at run time into VS2008 without having to use plld at the VS command prompt.

*** Special thanks to Alan Baljeu and joel76.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top