Here’s the issue:
I have a Prolog predicate doStuff(A, B, C) in my database.pl file, where A and C are inputs (it’s tacky but there’s a reason for it).
I have a C file to call this, and I’m able to compile and link them together without error. But when I actually try and run the executable, I get the following error:
Welcome to SWI-Prolog (threaded, 64 bits, version 10.0.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
ERROR: [Thread main] '$c_call_prolog'/0: Unknown procedure: doStuff/3
Exception: (1) doStuff(31, _13194, 15) ? creep
From the error message, SWI-Prolog is booting, it is correctly sending my predicate with the inputs where they belong and a variable where the output will be. But it seems like SWI-Prolog isn’t loading my database file.
I’ve tried rewriting my C file a number of ways, including:
predicate_t pred = PL_predicate("doStuff", 3, "user");
OR
// I tried making the database a module, and then doing:
predicate_t pred = PL_predicate("doStuff", 3, "module_name");
OR
predicate_t pred = PL_predicate("doStuff", 3, "path-to-file/database.pl");
I’m not sure if it’s relevant, but the term inputs are as follows:
term_t term0 = PL_new_term_refs(3);
term_t term1 = term0 + 1;
term_t term2 = term1 + 1;
PL_put_integer(term0, args[0]);
PL_put_variable(term1);
PL_put_integer(term2, args[1]);
int ret_val = PL_call_predicate(NULL, PL_Q_NORMAL, pred, term0)
Since things are going without error except for the predicate call, and since the predicate itself seems to be formatted correctly in the error message (and spelled correctly), it seems like I don’t know how to get the C file to load the database before executing the predicate call.
I’ll add that when I use swipl in the terminal and load the database, doStuff() works perfectly, so it isn’t an error with the predicate itself either.
Any help with this would be greatly appreciated!