Re: Problems using palloc in postgresql user C functions - Mailing list pgsql-novice

From Joe Conway
Subject Re: Problems using palloc in postgresql user C functions
Date
Msg-id 3E77FD4F.3040700@joeconway.com
Whole thread Raw
In response to Re: Problems using palloc in postgresql user C functions  (John Gunther <inbox@bucksvsbytes.com>)
Responses Re: Problems using palloc in postgresql user C functions
List pgsql-novice
John Gunther wrote:
> Thanks for the fast, late night answer. I've got that much. But when I
> compile and link my library with those statements (using libtool and
> gcc) I get "undefined reference" errors for the following: textin,
> textout, DirectFunctionCall1, CurrentMemoryContext,  MemoryContextAlloc,
> and pg_detoast_datum. Handling these errors is where my understanding
> fails? Can they be ignored somehow because they will be resolved at
> execution time? It looks like they're fatal and preventing the library
> from being created.
>

No, they can't be ignored. I'd guess you need the following includes at
a minimum:

#include "postgres.h"
#include "fmgr.h"

Beyond that, you may need:
#include "utils/builtins.h"

and if you are using SPI:
#include "executor/spi.h"

and possibly others.

The bottom line is you need to find the header file that defines the
functionality you want to use. I recommend you read:
http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/xfunc-c.html
(use the "Version-1 Calling Conventions for C-Language Functions" _not_
Version-0). And like I already mentioned, studying one or more of the
contrib libraries closely would be a very good idea.

Joe


pgsql-novice by date:

Previous
From: John Gunther
Date:
Subject: Re: Problems using palloc in postgresql user C functions
Next
From: Tom Lane
Date:
Subject: Re: Last access time for a table