Subject: Re: dynamic linking on FreeBSD (probably NetBSD as well)

From: Jan Wielemaker <[email-masked]>
Date: Fri, 13 Apr 2001 11:13:24 +0200

Brad,

[ CC'ed to the mailing list, to see whether there are any experts on these
  issues around
]

> You had wondered about the flags for dynamic linking on the Free|Net
> BSD.  I think the following flags should work for both (probably
> OpenBSD and BSD/OS 4.X (definitely *not* 3.X) as well):
> 
> 	gcc -o unix.so -shared -fPIC /usr/local/prolog/lib/pl-4.0.3/runtime/i386-freebsd4.3/libpl.a error.> o process.o 
> 
> I suspect there's a way to do with ld as well, but the appropriate ld
> incantations have always escaped me.  Of course, if it was early and I
> was still chipper, I would've elegantly used the -L and -l options.

I prefer using gcc anyhow, as it generally hides most of the ld and
platform problems from the user.

Together with the remarks below however, this worries me a bit.  On most
(sofar all but AIX) Unix systems creating a shared object can be done
without refering the object you're later going to link too.  With a
proper gcc installation the command should always be

	gcc -o object.so -shared object.o ...

-fPIC (and -fpic) are compilation options, so as long as you do not provide
any .c files you should not need it.  Sometimes you need to add -l<lib>
for required shared objects that are not required by Prolog itself (like
the X11 libraries are required by XPCE).

Adding libpl.a probably adds a good deal of the Prolog kernel to your
shared object.  That cannot be our goal.  You may check so using the nm
utility.

> I've included yet another change to a Makefile.in (in this case, I
> changed clib's).  It makes the build work if you haven't updated your
> PATH variable yet after a new install (or more appropriately, you're
> installing as root but working as a normal user. . .root's probably
> not gonna have the correct environment).  I haven't looked at the
> other packages, but I suspect they've similar issues.

That is an issue.  Currently you're obliged to have the target
installation directory in your PATH.  I'm afraid this will require
more changes though.

	--- Jan

> --Brad (who can't believe he's enjoying working on build issues)

:-)