0

I encountered error:

 "FATAL ERROR: Could not find system resources"

I then added the following code:

 putenv("SWI_HOME_DIR=/usr/lib/swi-prolog");

I ran into another problem of:

 "$c_call_prolog...Undefined procedure"

(More details here)

I ran the below command on Ubuntu 10.12

  sudo apt-get install swi-prolog build-essential.

I wrote a simple C program to test it but was not able to retrieve the return value from prolog. Suppose I want to interact with mortal.pl, I compiled with:

swipl-ld -o mmm mortal.c mortal.pl

no error but like I mentioned. I did not get what I expected.

I obtained another code, nothing weird on the code. This time I got the first error. It seems that if swi-prolog is set to that directory, it won't search for my predicate.

Where and what should I set this SWI_HOME_DIR?

fmendez
  • 7,250
  • 5
  • 36
  • 35
  • In conclusion...when I add putenv() to the code, the program behave exactly like when I compile the program w/o the prolog file (swipl-ld -o mmm mortal.c (enter)). It does not recognize the predicate. – user1699674 Apr 02 '13 at 04:45
  • Thank you...fmendez for excellently reformatting my post. ...In case this is relevant, I found the different another place which causes the could not find system resources...One w/o error calls PL_initialize(argc,argv)). The other calls PL_initialize(1, plav) where plav is the list of argv. – user1699674 Apr 02 '13 at 07:14
  • that could be Ubuntu 12.10, actually ? – CapelliC Apr 02 '13 at 09:40
  • @CapelliC you're right... 12.10 It also come to my attention that maybe I should simply ask what should be the value of the second parameter of PL_initialise(). Should it be the predicate name of the clause I want to use? i.e. mortal in this case. (And I need to specify it again when calling PL_predicate("mortal",1,"user"), need I not? – user1699674 Apr 03 '13 at 12:29
  • Should be argv, as documented. But I don't fully understand your problem. Do you have swipl installed? And your mortal.c embeds SWI-Prolog and has a main(int argc, char *argv[]) ? – CapelliC Apr 03 '13 at 12:41
  • This dummy mortal.c program is supposed to allow me to invoke mortal() predicate. "Now" there are 2 cases. 1. I called ./mmm only (passing the socrates inside the program). In return I got FATAL ERROR. Thus I came up with a proxy plav working as argv. 2. I called with ./mmm socrates, it answered me correctly if I supply PL_initialised with argv (which contains socrates.) Now I really think that this could be the setup problem. Some of the environment values must be missing ... but I do not know where to look for. – user1699674 Apr 04 '13 at 16:09

2 Answers2

1

(Recap) with

putenv("SWI_HOME_DIR=/usr/lib/swi-prolog");

I called

mmm socrates

I got

$c_call_prolog...Undefined procedure

w/o putenv, the same call returned

FATAL ERROR: Could not find system resources

I finally changed

PL_initialise(1, plav)

where plav[0] = "mortal"; plav[1] = NULL; to

PL_initialise(1, argv)

I am able to obtain True/False from

rval = PL_call_predicate(NULL, PL_Q_NORMAL, pred, h0);

Though this confuses myself. What does PL_initialise() expect then?...not a to be called predicate?

  • (in another word of my question), does it mean we should supply PL_initialise() with "socrates" as oppose to "mortal" because the one with PL_initialise(1,argv). – user1699674 Apr 04 '13 at 02:38
  • `argv[0]` must be the path of the executable process image, as received from OS at main() call. Not sure will help you, but the [C++ interface](http://www.swi-prolog.org/pldoc/package/pl2cpp.html) it's much easier to use. – CapelliC Apr 04 '13 at 16:18
0

No solution. I ended up installing ubuntu 12.10 64 bits (previously 32 bit). All those weird behavior are gone.