I am trying to compile some C extensions on a platform with Ubuntu 14.04 for Postgres 9.5.
In my case, I want to write my C code and first compile it into a standalone executable (as you can see from my Makefile below). This is because I also use the NumPy API and write functions that convert Postgres ArrayType into NumPy PyArray objects, and then use some functions of the NumPy array. It’s very difficult to get the right data, to properly release NpyIter objects, etc. Therefore, I definitely need to compile, run, observe errors and test everything before finalizing the details of how the library is built for the last part, where I say CREATE EXTENSION in Postgres .
When compiling, I get several undefined links , for example:
tmp.c:(.text+0x2d6): undefined reference to `get_typlenbyvalalign' tmp.c:(.text+0x346): undefined reference to `deconstruct_array' tmp.c:(.text+0x41f): undefined reference to `DatumGetFloat8' tmp.c:(.text+0x4ae): undefined reference to `pfree' tmp.c:(.text+0x4ba): undefined reference to `pfree'
These are server functions from the Postgres C API, but with lots of Googling and lots of synergy pgxs I can’t figure out how to get the name or path in the Postgres library, which I can’t link to.
Almost all requests are referred only to libpq , but these functions are not defined in this client API library, so I'm looking for something else.
For reference, here is the Makefile that I am currently using. Including the library directory from pg_config --libdir should also be incorrect, since it does not cause any changes to the original undefined errors.
INCLUDEDIRS := -I. INCLUDEDIRS += -I/usr/include/python2.7 INCLUDEDIRS += -I/home/username/anaconda/lib/python2.7/site-packages/numpy/core/include INCLUDEDIRS += -I$(shell pg_config --includedir-server) INCLUDEDIRS += -I$(shell pg_config --includedir) LIBS := -L$(shell pg_config --libdir) LIBS += -lpython2.7 tmp: tmp.c Makefile gcc tmp.c -o tmp $(INCLUDEDIRS) $(LIBS)
The output of pg_config --libdir :
user@computer :~/programming$ pg_config --libdir /usr/lib/x86_64-linux-gnu
I also found libpgcommon in this library directory, and when I add it to the Makefile, some of the undefined links disappear, but not all. They still remain:
tmp.c:(.text+0x2d6): undefined reference to `get_typlenbyvalalign' tmp.c:(.text+0x346): undefined reference to `deconstruct_array' tmp.c:(.text+0x41f): undefined reference to `DatumGetFloat8'
So pfree was found by linking to libpgcommon , but nothing else.
Digging even further, inside postgres.h I see where the DatumGetFloat8 macro is DatumGetFloat8 (line 662):
#ifdef USE_FLOAT8_BYVAL extern float8 DatumGetFloat8(Datum X); #else #define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X))) #endif
So, it should be that Postgres was installed in some way that used the USE_FLOAT8_BYVAL flag. Is this a standard? Do you expect from a simple installation of Postgres using batch repositories for a popular OS such as Ubuntu?
Given this, what other source code or library from which DatumGetFloat8 is extern 'd? For example, a Google search for "postgres DatumGetFloat8" sheds almost nothing shines on it. The best I can find is a message flow from 2011 , indicating (not sure if it is correct):
Missing DatumGetFloat8 reference implies server was built
with float8 pass by value and pljava was built with float8 pass by
Reference.
(the pljava bit doesn't matter to me).