Thread: How to add and use a static library within Postgres backend

How to add and use a static library within Postgres backend

From
XiaoChuan Yu
Date:
I'm doing some experimenting with the storage engine and I'd like to use a C++ static library (that has C headers).  I only need this to build on Ubuntu 64-bit for now.
How do I make postgres build with this library?
What changes do I need to make to the build system files?
I assume headers go in src/include but where do I put the library.a file?

Thanks,
Xiaochuan Yu

Re: How to add and use a static library within Postgres backend

From
Craig Ringer
Date:
On 27 November 2015 at 10:35, XiaoChuan Yu <xcyu.se@gmail.com> wrote:
I'm doing some experimenting with the storage engine and I'd like to use a C++ static library (that has C headers).  I only need this to build on Ubuntu 64-bit for now.
How do I make postgres build with this library?

Build it separately. Link to it like any other library. Take a look at configure.in for how libraries are discovered and the Makefile.am files for how the header path and linker flags are defined.

What changes do I need to make to the build system files?

As above. Look at how PostgreSQL uses existing libraries. If the library presents a pure C interface it should be just like everything else.
 
I assume headers go in src/include but where do I put the library.a file?

Don't copy anything into PostgreSQL's source tree. Add new linker path and include path entries so the build system knows how to find the files where you originally compiled them.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services