Foreign code with PL_assert

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);

I just got around the problem by calling assert in Prolog side. So this is no longer a problem. But I am still curious about PL_assert. I looked into the documentation about the explanation of the function, but is it not implemented? Or is the document obsolete?

You’re not saying what “not works” means. Crash? What else? One issue seems that MODULE is a char* while PL_assert() accepts a module handle. As not all declarations are in place it is hard to tell. Surely PL_assert() works. If it doesn’t for you, make a minimal example anyone can compile without having to guess on how to complete it. In this case it is particularly hard as you claim to use g++, but you use the C API. That is of course possible. It is not clear whether the cast operators from SWI-cpp.h are available or not.

When I used PL_assert, the linker complained that it could not find the reference. So to get around this problem, I just call assert inside of the prolog engine. I was not sure what the problem is. So I was suspicious whether there is a kind discrepancy between documents and the version I am using.

I did not use SWI-cpp.h because I used C-implementation. I called all functions in the C interface.
Thank you for your answer.

The symbol is there:

> nm -D src/libswipl.so | grep PL_assert
0000000000079390 T PL_assert

Could it be that the linker picks up some old version? PL_assert() was added in 8.1.32.