Re: [SWIPL] Is Cygwin special?

Jan Wielemaker wrote:
On Monday 16 January 2006 23:43, Roberto Bagnara wrote:
I have something that runs under GNU/Linux and does not run under Cygwin. It all boils down to something very simple. I have two files:
$ cat main.cc #include <SWI-Prolog.h>
int main(int, char** argv) { char* pl_args[2]; pl_args[0] = argv[0]; pl_args[1] = 0; if (!PL_initialise(1, pl_args)) PL_halt(1);
predicate_t pred = PL_predicate("mymain", 0, "user"); term_t h0 = PL_new_term_refs(0); int ret_val = PL_call_predicate(0, PL_Q_NORMAL, pred, h0); PL_halt(ret_val ? 0 : 1); } $ cat mymain.pl mymain :- write('mymain/0 called!'), nl.
I compile them under GNU/Linux:
$ g++ -I/usr/local/lib/pl-5.6.2/include -c main.cc $ plld -v -cc gcc -c++ g++ -ld g++ -o test.exe main.o mymain.pl eval `pl -dump-runtime-variables` CC="gcc" PLBASE="/usr/local/lib/pl-5.6.2" PLARCH="i686-linux" PLLIBS="-lgmp -ldl -lreadline -lncursesw -lm -lrt" PLLIB="-lpl" PLLDFLAGS="-export-dynamic -O3 -pthread" PLSOEXT="so" PLTHREADS="yes" g++ -o test.exe -export-dynamic -O3 -pthread main.o -L/usr/local/lib/pl-5.6.2/lib/i686-linux -lpl -lgmp -ldl -lreadline -lncursesw -lm -lrt pl -f none -F none -g true -t "consult(['mymain.pl']),qsave_program('pltmp-8678',[goal='$welcome',toplev el=prolog,init_file=none])" % mymain.pl compiled 0.00 sec, 2,004 bytes % halt cat pltmp-8678 >> test.exe chmod 775 test.exe rm pltmp-8678
I compile them in exactly the same way under Cygwin (note: same version of SWI-Prolog, configured in the same way and installed in the same place):
$ g++ -I/usr/local/lib/pl-5.6.2/include -c main.cc $ plld -v -cc gcc -c++ g++ -ld g++ -o test.exe main.o mymain.pl eval `pl -dump-runtime-variables` % mymain.pl compiled 0.00 sec, 1,984 bytes % halt CC="gcc" PLBASE="/usr/local/lib/pl-5.6.2" PLARCH="i686-cygwin" PLLIBS="-lgmp -lreadline -lncurses -lm -lpthread" PLLIB="-lpl" PLLDFLAGS="-export-dynamic -O3" PLSOEXT="dll" PLTHREADS="yes" g++ -o test.exe -export-dynamic -O3 main.o -L/usr/local/lib/pl-5.6.2/lib/i686-cygwin -lpl -lgmp -lreadline -lncurses -lm -lpthread pl -f none -F none -g true -t "consult(['mymain.pl']),qsave_program('pltmp-3416.exe',[goal='$welcome',to plevel=prolog,init_file=none])" cat pltmp-3416.exe >> test.exe chmod 755 test.exe rm pltmp-3416.exe
However, when I run the result under GNU/Linux I get:
$ ./test.exe Welcome to SWI-Prolog (Multi-threaded, Version 5.6.2) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
mymain/0 called! $
When I run under Cygwin I get:
$ ./test.exe Welcome to SWI-Prolog (Multi-threaded, Version 5.6.2) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
ERROR: Undefined procedure: mymain/0
What am I missing?
Maybe something is going wrong in text/binary mode handling of creating the combined executable. I do not have Cygwin (and no intention of installing it). First, try "plrc l text.exe" to check the associated resources.
This is what I obtain (both under Cygwin and GNU/Linux): $ plrc l test.exe size class encoding name 795514 $rc none $header 172 $prolog none $options 105419 $prolog none $state
You can also check some cross-platform tricks. "pl -x test.exe" should load mymain as long as pl is running on the native platform regardless of the platform test.exe was created on.
This is on Cygwin:
$ pl -x test.exe Welcome to SWI-Prolog (Multi-threaded, Version 5.6.2) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?- mymain. mymain/0 called!
Yes 2 ?-
% halt
This is on GNU/Linux:
$ pl -x test.exe Segmentation fault $ gdb /usr/local/bin/pl GNU gdb Red Hat Linux (6.3.0.0-1.84rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r -x test.exe Starting program: /usr/local/bin/pl -x test.exe Reading symbols from shared object read from target memory...done. Loaded system supplied DSO at 0x939000 [Thread debugging using libthread_db enabled] [New Thread -1208862240 (LWP 3614)]
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208862240 (LWP 3614)] 0x08090b1a in garbageCollect () (gdb) info stack #0 0x08090b1a in garbageCollect () #1 0x0806570f in PL_next_solution () #2 0x080a3746 in prologToplevel () #3 0x080dbb09 in PL_initialise () #4 0x08050706 in main () (gdb)
Does this shed any light? Thanks a lot for your help,
Roberto

Roberto,
On Tuesday 17 January 2006 11:18, Roberto Bagnara wrote:
You can also check some cross-platform tricks. "pl -x test.exe" should load mymain as long as pl is running on the native platform regardless of the platform test.exe was created on.
This is on Cygwin:
$ pl -x test.exe Welcome to SWI-Prolog (Multi-threaded, Version 5.6.2) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?- mymain. mymain/0 called!
Yes 2 ?-
test.exe was created on Linux?
This is on GNU/Linux:
$ pl -x test.exe Segmentation fault
This test.exe was created on Cygwin? The crash in garbageCollect() suggests there is something very wrong with the saved state sitting at the end of text.exe. There are two options. One is that saved states do not work on Cygwin and the other is that the assembly of the executable and the state (simple concatenation) is wrong. The first can be tested by writing a state using pl -o state -c file.pl and see whether you can run the result with "pl -x state" (state should run using both the Linux and the Cygwin emulator). I'm suspecting some text/binary file issue that either corrupts the state or the concatenation. Resource files are manipulated through the code in pl/src/rc. There are three implementations, one based on classical read/write, one based on Unix mmap() and one based on Windows CreateFileMapping().
Cheers --- Jan

Jan Wielemaker wrote:
Roberto,
On Tuesday 17 January 2006 11:18, Roberto Bagnara wrote:
You can also check some cross-platform tricks. "pl -x test.exe" should load mymain as long as pl is running on the native platform regardless of the platform test.exe was created on.
This is on Cygwin:
$ pl -x test.exe Welcome to SWI-Prolog (Multi-threaded, Version 5.6.2) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?- mymain. mymain/0 called!
Yes 2 ?-
test.exe was created on Linux?
On Cygwin. (But see at the end of the message what happens if I try to use on Cygwin a test.exe created on Linux.)
This is on GNU/Linux:
$ pl -x test.exe Segmentation fault
This test.exe was created on Cygwin? The crash in garbageCollect() suggests there is something very wrong with the saved state sitting at the end of text.exe. There are two options. One is that saved states do not work on Cygwin and the other is that the assembly of the executable and the state (simple concatenation) is wrong. The first can be tested by writing a state using pl -o state -c file.pl and see whether you can run the result with "pl -x state" (state should run using both the Linux and the Cygwin emulator).
On Cygwin:
$ pl -o state -c mymain.pl % mymain.pl compiled 0.00 sec, 1,984 bytes
$ pl -x state Welcome to SWI-Prolog (Multi-threaded, Version 5.6.2) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?- mymain/0 called!
Yes 2 ?-
% halt $
However, if I copy `state' to GNU/Linux: $ gdb /usr/local/bin/pl GNU gdb Red Hat Linux (6.3.0.0-1.84rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r -x state Starting program: /usr/local/bin/pl -x state Reading symbols from shared object read from target memory...done. Loaded system supplied DSO at 0xca2000 [Thread debugging using libthread_db enabled] [New Thread -1208210976 (LWP 4127)]
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208210976 (LWP 4127)] 0x08090b1a in garbageCollect () (gdb) info stack #0 0x08090b1a in garbageCollect () #1 0x0806570f in PL_next_solution () #2 0x080a3746 in prologToplevel () #3 0x080dbb09 in PL_initialise () #4 0x08050706 in main () (gdb)
I'm suspecting some text/binary file issue that either corrupts the state or the concatenation. Resource files are manipulated through the code in pl/src/rc. There are three implementations, one based on classical read/write, one based on Unix mmap() and one based on Windows CreateFileMapping().
I have made another test. I have generated `test.exe' on GNU/Linux and copied it to Cygwin, then, on Cygwin, I tried
$ pl -x test.exe $
So I get the shell prompt back, not SWI-Prolog's prompt. Thanks again,
Roberto
participants (2)
-
Jan Wielemaker
-
Roberto Bagnara