[PPL-devel] Re: [SWIPL] Is Cygwin special?

Roberto Bagnara bagnara at cs.unipr.it
Tue Jan 17 11:18:54 CET 2006


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

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it



More information about the PPL-devel mailing list