List manipulation when interfacing c++ and prolog

I am having some issues with manipulating lists when interfacing C++ and Swi-Prolog. I’m using: SWI-Prolog version 8.2.0.

I have a Prolog file containing the single fact:

test([foo,bar]).

and I have the following c++ function for building a list:

int main(int argc, char **argv)
{
    PlEngine e(argv[0]);
    PlTermv av(1);
    PlTail my_list(av[0]);
    my_list.append("foo");
    my_list.append("bar");
    my_list.close();
    
    if ( PlCall("test", my_list) )
      cout << 1;
    else
        cout << 0;
    
    exit(1);
}

At this stage, I want to check the list I am building is [foo,bar]. However, running this script returns 0 - I am compiling and executing both the cpp and pl file. Could you please advice on how to build and manipulate lists? Am I missing something about how the append function and PlTail class behave?

Thanks!

This is cross-posted at StackOverflow.