Re: [HACKERS] compiling extension functions? (fwd) - Mailing list pgsql-hackers

From Thomas G. Lockhart
Subject Re: [HACKERS] compiling extension functions? (fwd)
Date
Msg-id 34E25F00.F763B623@alumni.caltech.edu
Whole thread Raw
In response to compiling extension functions? (fwd)  (Tripp Lilley <tlilley@perspex.com>)
List pgsql-hackers
> I'm trying to compile and use a 'C' extension function for PG 6.2.1 under
> Red Hat Linux 4.2 (stock distribution). I am executing the following
> commands to compile my shared library and install my function, but I get
> "Unable to resolve symbol" when I try to execute the function.
>
> > gcc -fpic -shared salmon.c -o salmon.so -L/usr/lib -lpq
> -I/usr/include/postgres
> > touch salmon.sql
> > psql -d nim_0_01 -f salmon.sql
> drop function salmon (int4);
> DROP
>
> create function
>                 salmon (int4)
>         returns
>                 char16
>         as
>                 '/home/tlilley/projects/perspex/scratch/nim/salmon.so'
>         language
>                 'c';
> CREATE
> EOF
>
> > psql -d nim_0_01
>
> nim_0_01=> select salmon( 42 );
> WARN:Load of file /home/tlilley/projects/perspex/scratch/nim/salmon.so
> failed: Unable to resolve symbol
> nim_0_01=>
>
> And here's the source for my function:
>
> #include <postgres.h>
> #include <utils/palloc.h>
>
> char16 * salmon (int4 value)
> {
>   char16 * buffer = (char16 *) palloc( sizeof( char16 ) );
>
>   memset( (void *) buffer, 0, sizeof( char16 ) );
>   (void) strncpy( buffer, "hello", 16 );
>   return( buffer );
> }
>
> Any help (especially 'working' compile command-lines) would be great!

Look in contrib/int8/ for code and Makefile which were developed on RH Linux
4.2. ld may not be finding the libraries it needs. You may need to set
LD_LIBRARY (or something like that, don't remember the name exactly) and/or
modify /etc/ld.so.conf then run ldconfig to get the load library database
pointing at the Postgres libraries.

Good luck.

                                                               - Tom


pgsql-hackers by date:

Previous
From: t-ishii@sra.co.jp
Date:
Subject: MB patch
Next
From: "Thomas G. Lockhart"
Date:
Subject: Re: [HACKERS] sum(population) under Sybase