Обсуждение: compiling extension functions? (fwd)

Поиск
Список
Период
Сортировка

compiling extension functions? (fwd)

От
Tripp Lilley
Дата:
I posted this to questions a few days back but got no response. Can anyone
here help me with this? I know it should be straightforward, and that I'm
missing something obvious, but precisely *what* I'm missing is unknown to
me.

Thanks!

- t.

-----------------------------------------------------------------------
   Tripp Lilley, Perspex Imageworks, Inc. (tripp.lilley@perspex.com)
-----------------------------------------------------------------------
      "Give me a fast computer, for I intend to go in harm's way"
                      - updating John Paul Jones

---------- Forwarded message ----------
Date: Mon, 9 Feb 1998 12:42:48 -0500 (EST)
From: Tripp Lilley <tlilley@perspex.com>
To: pgsql-questions@postgresql.org
Subject: compiling extension functions?

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!

Thanks...

- t.

-----------------------------------------------------------------------
   Tripp Lilley, Perspex Imageworks, Inc. (tripp.lilley@perspex.com)
-----------------------------------------------------------------------
      "Give me a fast computer, for I intend to go in harm's way"
                      - updating John Paul Jones



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

От
"Thomas G. Lockhart"
Дата:
> 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