Compiling in Windows with swipl-ld

Trying to compile a 32bit DLL in Windows 10 with swipl-ld (SWI-Prolog 8.0.2-1 32bit stable), there is an error with a reference to /usr/bin/i686-w64-mingw32-gcc (as reproduced below), which is not a usual path for Windows. The same procedure was working with SWI-Prolog 7.6.4. Do you have any hint what is happening? Thank you in advance.

mingw32-make[1]: Entering directory 'c:/Bousi-Prolog/extern'
swipl-ld -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"%GNUWIN32%\include" -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -shared -fPIC -pl swipl -o extern.dll closure.c fuzzysets.c array.c lexical.c tokenize.c blocks.c leditwin.c shell.c install.c
El sistema no puede encontrar la ruta especificada.
/usr/bin/i686-w64-mingw32-gcc returned code 1
*** swipl-ld exit status 1

P.S. The (Spanish) error message above says something like: "The system cannot find the given path"

I see. You can use swipl-ld -cc gcc ... as a work around. I think there is also an outstanding issue with the library directory it passes though :frowning:

I start to have my doubt about the entire concept of swipl-ld We already have a swipl.pc for pkg-config. Now this doesn’t fit Windows very well (I think). We could add a FindSWI-Prolog.cmake to support CMake users. I have little clue about what Windows users expect for compiling against externally installed software.

Thanks. I have tried that flag and the reference to the same path still persists:

C:\Bousi-Prolog\extern>swipl-ld -cc gcc -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"%GNUWIN32%\include" -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -shared -fPIC -pl swipl -o extern.dll closure.c fuzzysets.c array.c lexical.c tokenize.c blocks.c leditwin.c shell.c install.c
closure.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
fuzzysets.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
array.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
lexical.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 #line 2 "lexical.c"
 ^
tokenize.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
blocks.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
leditwin.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
shell.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
install.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
El sistema no puede encontrar la ruta especificada.
/usr/bin/i686-w64-mingw32-gcc returned code 1
*** swipl-ld exit status 1

This is legacy code and I’m also not sure what expect for compiling such software.

You probably also need -ld gcc. Add -v to see what it is trying to do.

Thanks, I think this parameter fixes some things:

swipl-ld -cc gcc -ld gcc -v -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"%GNUWIN32%\include" -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -shared -fPIC -pl swipl -o extern.dll closure.c fuzzysets.c array.c lexical.c tokenize.c blocks.c leditwin.c shell.c install.c
        eval `swipl --dump-runtime-variables`
                PLBASE="c:/program files (x86)/swi-prolog 8.0.2"
                PLARCH="i386-win32"
                PLSOEXT="dll"
                PLLIBDIR="c:/program files (x86)/swi-prolog 8.0.2/lib/i386-win32"
                PLLIB="-lswipl"
                PLTHREADS="yes"
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o closure.o closure.c
closure.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o fuzzysets.o fuzzysets.c
fuzzysets.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o array.o array.c
array.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o lexical.o lexical.c
lexical.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 #line 2 "lexical.c"
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o tokenize.o tokenize.c
tokenize.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o blocks.o blocks.c
blocks.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o leditwin.o leditwin.c
leditwin.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o shell.o shell.c
shell.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -c -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-unused-result -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -fPIC -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -I"c:/program files (x86)/swi-prolog 8.0.2/include" -I"c:/program files (x86)/swi-prolog 8.0.2\include" -I"C:\Program Files (x86)\GnuWin32\include" -o install.o install.c
install.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /***********************************************************************
 ^
        gcc -o extern.dll -shared closure.o fuzzysets.o array.o lexical.o tokenize.o blocks.o leditwin.o shell.o install.o -L"c:/program files (x86)/swi-prolog 8.0.2/lib/i386-win32" -lswipl
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lswipl
collect2.exe: error: ld returned 1 exit status
gcc returned code 1
        rm closure.o
        rm fuzzysets.o
        rm array.o
        rm lexical.o
        rm tokenize.o
        rm blocks.o
        rm leditwin.o
        rm shell.o
        rm install.o
*** swipl-ld exit status 1

There is still an issue with a directory, I noticed that

PLLIBDIR="c:/program files (x86)/swi-prolog 8.0.2/lib/i386-win32"

refers to a non-existent directory or file:

C:\Bousi-Prolog\extern>dir "c:/program files (x86)/swi-prolog 8.0.2/lib"
 El volumen de la unidad C es OS
 El número de serie del volumen es: 388E-6F34

 Directorio de c:\program files (x86)\swi-prolog 8.0.2\lib

05/03/2019  22:19    <DIR>          .
05/03/2019  22:19    <DIR>          ..
05/03/2019  13:07            32.035 jpl.jar
               1 archivos         32.035 bytes
               2 dirs  88.666.873.856 bytes libres

Just pushed 0195e496c8ea05c40e05b5bf13f00b9307ae9e1c and d46a4afe8c1593e0edd4f19d902ded77925d83eb to deal with setting the C compiler to gcc.exe and fixing the library directory. Should be in tomorrows daily build at http://www.swi-prolog.org/download/daily/bin/

We’ll see …

As a work-around you can add a -L pointing at the right directory. The value of swipl-ld.exe is small if you have to overrule all defaults though :frowning:

Many thanks, Jan. I was able to compile with that flag. Tomorrow, I’ll try the night build and keep you informed. All the best

The daily build swipl-w32*2019-03-07.exe for Windows 32bit compiled the DLL like a charm. Many thanks!