I’m using: SWI-Prolog version ??? swipl 8.3.19
I want the code to: Want to compile c++ code with Prolog.
But what I’m getting is: Compilation complains that PL_assert function is not undefined reference. I tried both g++ and swipl-ld as the compiler. They have the same error message.
If PL_assert does not work, I will try to call assert in Prolog but why PL_assert function is not working?
My code looks like this:
% your code here
predicate_t consult = PL_predicate("consult", 1, (const char*)MODULE);
term_t model = PL_new_term_ref();
term_t submodel = PL_new_term_ref();
term_t solver = PL_new_term_ref();
pls = PL_chars_to_term(CPMODEL.data(), model);
pls = PL_chars_to_term(CPSUBMODEL.data(), submodel);
pls = PL_chars_to_term(CPSOLVER.data(), solver);
pls = PL_call_predicate(MODULE, PL_Q_NORMAL, consult, model);
pls = PL_call_predicate(MODULE, PL_Q_NORMAL, consult, submodel);
pls = PL_call_predicate(MODULE, PL_Q_NORMAL, consult, solver);
term_t lb_term = PL_new_term_ref();
term_t ub_term = PL_new_term_ref();
term_t nbstates_term = PL_new_term_ref();
term_t lbval = PL_new_term_ref();
term_t ubval = PL_new_term_ref();
term_t nbstatesval = PL_new_term_ref();
pls = PL_put_integer(lbval, lb);
pls = PL_put_integer(ubval, ub);
pls = PL_put_integer(nbstatesval, nb_states);
functor_t lb_f = PL_new_functor(PL_new_atom("lb"), 1);
functor_t ub_f = PL_new_functor(PL_new_atom("ub"), 1);
functor_t nbstates_f = PL_new_functor(PL_new_atom("nbstates"), 1);
pls = PL_cons_functor(lb_term, lb_f, lbval);
pls = PL_cons_functor(ub_term, ub_f, ubval);
pls = PL_cons_functor(nbstates_term, nbstates_f, nbstatesval);
pls = PL_assert(lb_term, MODULE, PL_ASSERTZ);
pls = PL_assert(ub_term, MODULE, PL_ASSERTZ);
pls = PL_assert(nbstates_term, MODULE, PL_ASSERTZ);