Subject: Re: Linking SWI-Prolog with Link Grammar Parser v4.0

From: Lionel Ains <[email-masked]>
Date: Tue, 8 Aug 2000 15:33:31 +0100 (WET DST)

Hi all,

finally, it works!
When I execute the program with plwin, everything is fine and the dll is loaded without any problem.
When I try to load the same program with plcon, it crashes after executing the entry point of the 
DLL and registering the foreign language library with the initialisation routine given through 
load_foreign_library/2 second parameter.

To get the working compiled DLL, I use the following compiling command with gcc under Cygwin:
gcc -I /cygdrive/c/Program\ Files/SWI-Prolog/include/ -I include/ -c src/lgp.c -o obj/lgp.o
Where /cygdrive/c/Program\ Files/SWI-Prolog/include/ is the posix path where SWI-Prolog's include 
directory is mounted.
include/ contains application-specific include files and src/lgp contains the code for the foreign 
language library (including a main() and the foreign initialisation routine).

Then, I can create the dll, from the object file lgp.o, linking it with cygwin1.dll (which is thus also 
necessary to run the foreign language library):
gcc -shared -o obj/lgp.dll obj/*.o /cygdrive/c/Program\ Files/SWI-prolog/bin/LIBPL.DLL
The path to LIBPL.DLL must of course be adapted to the posix path where LIBPL.DLL can be found 
(this is part of the SWI-Prolog native directory).

plcon still crashes when I try to load the foreign language interface by consulting the source file on the 
Prolog command line. However, if I use the following command-line for plcon:
C:\WINNT\Profiles\lains\Prolog>"C:\Program Files\SWI-Prolog\bin\plcon" -g "load_files(['prog.pl']), 
write('Program loaded'), nl, qsave_program('prog.exe', [goal=go, toplevel=none, stand_alone=true]), 
write('Program successfully saved'), nl" -t halt.
The Prolog engine doesn't crash, I have the two "Program loaded" and "Program successfully saved" 
messages and finally I get an executable which runs properly!

There is maybe a bug in that story (plcon), but I managed to make it work this way at the end of the 
day.

Lionel

> -------Message d'origine-------
> De : Lionel Ains <[email-masked]>
> Date : 01/08/100 19:55:08
> 
> Hello
> 
> I have decided DLLs to link the foreign code to the Prolog engine.
> I'm using cygwin for Windows NT, and compiling my DLL with gcc under cygwin.
> Using the two lines given inside the manual, the prolog Engine crashes when executing 
> load_foreign_library/1. I have thus used another description I found about bulding a DLL with 
cygwin.
> Here are the commands I use (assuming that t.c is the foreign language source code):
> gcc -I/cygdrive/c/Program\ Files/SWI-Prolog/include -c t.c
> echo -e "EXPORTS\npl_lowercase\ninstall" > libt.def
> gcc -s -Wl,--base-file,libt.base -o libt.dll t.o /cygdrive/c/Program\ Files/SWI-Prolog/bin/Libpl.dll 
> -Wl,-e,_install
> dlltool --base-file libt.base --def libt.def --output-exp libt.exp --dllname libt.dll
> 
> The source file consists of the exmaple lowercase/2 predicate (chap 5.9), slightly modified to adapt 
to 
> cygwin.
> This gives me a library libt.dll
> When I try load_foreign_library(libt). under SWI-Prolog, I get immediately a Yes. without any output 
of 
> the debug messages included in install, which means that lowercase is not registered, and the 
failure 
> when calling lowercase/2 confirms it.
> 
> I've first tried the default compilation commands (figure 5.7 chap 5.9), it generates the dll but when I 
> call load_foreign_library(libt), I have the two debugging messages "Starting install function of 
library" 
> and "Exiting install function of library" and Prolog hangs.
> 
> Does someone have a preceding experience concerning cygwin, or would there be another free C 
> compiler that could do the job?
> 
> Thanks a lot,
> 
> Lionel 
______________________________________________________
Boîte aux lettres - Caramail - http://www.caramail.com