The code that uses PL_foreign_in_module() hasn’t changed in a long time.
I don’t use Windows, but from the error message, it appears that the message refers to the “mangled” form of the name (C++ “mangles” function names with extra information about the type, to allow overloading etc). This shouldn’t happen if your definition of PL_foreign_in_module() is inside a extern "C" { ... } block - which is what SWI-Prolog.h has. Perhaps you have either an ancient version of SWI-Prolog.h or a copy that has removed the extern "C"? (Unlikely that it’s ancient: the extern "C" was added 28 years ago.)
The most likely reason for those errors is a corrupted SWI-Prolog.h file. Version 8.5.13 is over a year old, so you might want to update to the latest (8.5.20 or 9.1.15) and verify your SWI-Prolog.h. It’s also possible that you have a bad SWI-Prolog.h in your include path – you can check this by deliberately putting a syntax error in the file you think is being included and see if you get a compile error.
(I’m sorry I can’t help more – I wrote SWI-cpp2.h but I use Linux, not Windows.)
Your little test program worked fine for me with gcc 13.2.0, but it should give the same result with earlier versions because, as far as I know, the object file formats and name-mangling haven’t changed:
$ cat ttt.cpp
#include <SWI-cpp.h>
PREDICATE (check,2) {
PL_succeed;
}
$ swipl-ld -shared ttt.cpp -o ttt.so
$ file ttt.so
ttt.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=f7a95c7ea89fd036b08d82e21a5fed969c733b62, not stripped
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.15-2-ge5af93f95-DIRTY)
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).
?- use_foreign_library(ttt).
true.
?- check(A,B).
true.
?-
% halt
If there’s information missing from the page for building with Windows, please add it here or submit a change, so that others don’t run into the problems you experienced.