which should produce test.dll. A lot of stuff can go wrong though, especially on Windows. First, add -v to the above options and check it actually calls the right mingw-gcc and you create a matching dll (32/64 bit).
when I run this command, such error happen. So I changed the command. I also tried compile in Visual Studio and link using swipl-ld. As I also try to link using Visual Studio, I can’t find swipl.lib and swipl.dll
PS C:\Xiaojun\packages-cpp> swipl-ld -o test -shared test.cpp -v
eval `swipl.exe --dump-runtime-variables`
PLBASE="c:/xiaojun/swipl"
PLARCH="x64-win64"
PLSOEXT="dll"
PLLIBDIR="c:/xiaojun/swipl/bin"
PLLIB="-lswipl"
PLTHREADS="yes"
g++.exe -c -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -Ic:/xiaojun/swipl/include -o test.obj test.cpp
g++.exe -o test.dll -shared test.obj -Lc:/xiaojun/swipl/bin -lswipl
Preformatted text`Preformatted text c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/xiaojun/swipl/bin/libswipl.dll.a: error adding symbols: file format not recognized
collect2.exe: error: ld returned 1 exit status
g++.exe returned code 1
rm test.obj
*** C:\Xiaojun\swipl\bin\swipl-ld.exe exit status 1
Which nicely creates test.dll. SWI-Prolog can also load it, but it refuses to work as the predicates are not installed. Possibly something with handling C++ constructors? I’m mostly on alien territory here. Possibly some Windows user knows how to do this.
I think it is also possible to create a .lib file, but I’m not sure how. This has changed several times.
If you are compiling for 64-bit architecture, you could try to use mingw-w64.
There is mentioned on MinGW releases site that they are offering a 32-bit compiler only.