Embedding prolog engine in a dll

"Marwen Belkaid" <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi everybody !

I tried to post almost the same question a few days ago and I think it is
still waiting for moderator approval for I hadn't subscribed to the
mailing list yet. I apologize if any redundancy results for this message.

I am trying to create a C++ API for the embedded prolog engine I've been
working on till now so another program could use the logic with no need to
compile any prolog code. It is ok if some swipl lib and dll files are
required though. So since I am quite new to DLL development I started with
a simple example based on the likes.pl sample file provide by swi-prolog.
Then, likes.cpp would contain a function that calls PlQuery and be used to
generate the DLL. Finally, food.cpp contains the main() function that
would call the DLL function to list the food sam likes.

I've been trying several things and I think I am getting pretty close but
can get it to work. For instance:
*food.cpp :
int main(int argc, char *argv[])  {
	char* av[15];
	av[0] = (char*)"mystate.exe";
	if(!PL_initialise(1, av))
		cout << "NO init\n" ;
	else
		cout << "OK init\n" ;
	cout << "Food:\n" ;
	cout <<  get_food() ;
	getchar();
	return 0;
}
*likes.cpp:
string LIKESCALL get_food() {
	string result ;
	PlTermv av(2);
	PlEngine prolog((char*)"mystate.exe");
	av[0] = PlCompound("sam");
	PlQuery q("likes", av);
	while (q.next_solution())
	{
		string tmp((char*)av[1]);
		result.append(tmp);
		result.push_back('\n');
	}
	return result;
}
Then:
    swipl --goal=true --stand_alone=true -o mystate -c likes.pl
    swipl-ld -shared -dll -o likes -goal true likes.cpp likes.pl
-DLIKES_EXPORTS -v
    g++ -o food.exe food.cpp -L"c:/program files (x86)/swipl/lib" -lswipl
-I"c:/program files (x86)/swipl/include" -L. -llikes -I.
Here I get the following error :
  error(existence_error(procedure,likes/2),context(system:$c_call_prolog/0,_G89))

What am I doing wrong ? How an where exactly should I initialize PEngine ?
How do I have to save and use the program state ? why doesn't the linker
handle the state when the output is a DLL ?

I would really appreciate some help. Thanks a lot !
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.