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

From John Gunther
Subject Re: Problems using palloc in postgresql user C functions
Date
Msg-id 3E781315.1050700@bucksvsbytes.com
Whole thread Raw
In response to Re: Problems using palloc in postgresql user C functions  (Joe Conway <mail@joeconway.com>)
Responses Re: Problems using palloc in postgresql user C functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
I haven't been explaining my exact problem clearly, but looking at your
tablefunc, I'm sure the issue is just a simple conceptual gap on my part.

In line with your responses, I'm already supplying my library with the
prototypes for all the needed PG functions, like textin. The problem is
when compiling and linking, how does libtool/gcc find or point to the
actual code for textin so it can execute it when needed. That is, the
compiler knows what textin is and the types of its arguments, but how
does it know where it is? That's what the "undefined reference" errors
are denoting. Clearly there's a way, since tablefunc doesn't include the
source code for textin, even though it calls that function. I'm just too
new to gcc to know what it is.

Joe Conway wrote:

> 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: Tom Lane
Date:
Subject: Re: Last access time for a table
Next
From: Tom Lane
Date:
Subject: Re: Problems using palloc in postgresql user C functions