users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Prolog not fully initialized


From: Michał Bieliński
Subject: Re: Prolog not fully initialized
Date: Tue, 11 Jun 2013 23:08:26 +0200
User-agent: SquirrelMail/1.4.21

Dnia 8 Czerwca 2013, 16:40, So, cschick napisał(a):
> The post is more than 2 years old, but I've had the same problem
> and wanted to share what I've found out.

You're welcome.  Wait, much more than welcome since you bring a complete
solution.

> The main point seems to be to ask gcc to call the constructors.

Or calling it from Free Pascal.  Two years ago I modified linker script
and had ld make address of .ctors section global.  Then in Pascal code I
declared an array of procedures beginning right there using absolute
directive.  A loop iterating over that executing every pointed function
ensured every atom was available.

This worked but was very unstable.  Any upgrade of gcc, ld, fpc or even
some accompanying libraries tended to break it.  Thus I decided against
sharing that solution.

> I've succeded by creating a dynamic library where gcc seems to
> initialize them correctly.

Congratulations, and thank you!  I made some modifications to suit my
needs which you may want to take advantage of.

> I needed a little C snippet to interface some of the funtions
> to get GProlog to work.

I did away with this.  There is no need for C to negotiate between the lib
and Pascal.

{$librarypath /usr/share/gprolog/lib}
{$linklib bips_pl}

Pl_Query_Begin, Pl_Query_Call and Pl_Query_End can be found libbips_pl.a.
Linking it from the Pascal side too solves the undefined reference.

> The main task is done by the shell script "makefile.sh".

I converted this to proper GNU Makefile to avoid recompilation of the
helper library.

> Remarks:
> 1) I needed libgcc.a to be present in the directory where I
> compiled the program. Maybe someone could find out how this
> can be omitted.

Removing these from Pascal code does it for me:
> {$linklib c}
> {$linklib gcc.a}

The program compiles just fine without them.

> 2) I needed to append LD_LIBRARY_PATH so as to point to
> the directory where the dynamic library is. I hope this
> can be omitted, too.

Indeed.  You call fpc like this:
> fpc pas_pl.pas

Free Pascal compiler accepts -k parameter which passes an option directly
to linker.  With it you may extend resulting program's library search path
by current directory.  Here is how:

fpc pas_pl.pas -k'-rpath .'

For Free Pascal to find the .so I added:
{$librarypath .}

> 3) The directories pointing to gprolog-1.4.0 need to be
> changed to suit your needs.

Yeah.  The path is '/usr/share/gprolog/lib' for me.

> 4) The post is rather long, I'm not too used to mailing lists.

Well, quadruple post does raise a tiny suspicion. :-)

> {It does now a bit better... May 1st, 2013...except for hello, which
> (obviously) was not specified}

Oops.  Long ago I modified my new_main.pl to include following two lines:

hello :-
    write('hello world'), nl.

Then promptly forgot that was not in the original.

> {$linklib my_prolog_library.so}

I had to rename generated shared object to libmy_prolog_library.so.  It
was not found otherwise.

Thanks again!  It is good to have a clean, stable solution for GNU Prolog
to work with Free Pascal.

-- 
Michał Bieliński




reply via email to

[Prev in Thread] Current Thread [Next in Thread]