Re: Problems using palloc in postgresql user C functions

From: Joe Conway <mail(at)joeconway(dot)com>
To: John Gunther <inbox(at)bucksvsbytes(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Problems using palloc in postgresql user C functions
Date: 2003-03-19 05:17:03
Message-ID: 3E77FD4F.3040700@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2003-03-19 05:32:18 Re: Last access time for a table
Previous Message John Gunther 2003-03-19 04:51:59 Re: Problems using palloc in postgresql user C functions