Re: [HACKERS] compiling extension functions? (fwd)

From: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
To: Tripp Lilley <tlilley(at)perspex(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] compiling extension functions? (fwd)
Date: 1998-02-12 02:31:28
Message-ID: 34E25F00.F763B623@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas G. Lockhart 1998-02-12 02:44:55 Re: [HACKERS] sum(population) under Sybase
Previous Message t-ishii 1998-02-12 02:10:58 MB patch