Re: PG Extensions: Must be statically linked?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PG Extensions: Must be statically linked?
Date: 2006-03-03 16:02:22
Message-ID: 20060303160222.GC17615@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 03, 2006 at 07:46:06AM -0800, Craig A. James wrote:
> Thanks for your answers -- see below.
>
> Based on Peter's and Tom's replies regarding C++, I think you've answered
> my question: I should be able to do this without static linking. But the
> Postgres linker uses the C (not the C++) linker to resolve references, so
> it's not finding the C++ libraries.

<snip>

> So now my question is: Can I somehow add other directories/libraries to
> those that Postgres uses? Or is there an option for Postgres use the C++
> dynamic linker? I don't mind statically linking OpenBabel, but it seems
> like a bad idea to put the specific version- and system-dependent location
> of libstdc++.a into my makefiles.

There are a number of ways to indicate which extra libraries to load,
but by far the easiest is by specifying them on the link line.

Your problem is that when creating a shared library, you are not
required to make sure all your external symbols are defined somewhere.
You didn't post your compile/link line but if you're using C++ you
probably need to use g++ for the linking to include the special C++
libraries.

One way to find out what's going on is using readelf:

$ readelf -a /bin/bash |grep NEEDED
0x00000001 (NEEDED) Shared library: [libncurses.so.5]
0x00000001 (NEEDED) Shared library: [libdl.so.2]
0x00000001 (NEEDED) Shared library: [libc.so.6]

These are the libraries that will be loaded when someone tries to load
your shared lib (the above works on any ELF object). The easiest is to
specify "--no-undefined" on the link line so the linker checks up front
you won't get undefined symbols at run time. Remember it's
-Wl,--no-undefined if invoking from gcc/g++.

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas DCP SD 2006-03-03 16:20:29 Re: Automatic free space map filling
Previous Message James_Hughes 2006-03-03 15:54:02 Re: Initdb on Windows 2003