Creating server-side functions: one simple error - Mailing list pgsql-bugs

From Ruslan A Dautkhanov
Subject Creating server-side functions: one simple error
Date
Msg-id 3DA4157A.1DA9078C@scn.ru
Whole thread Raw
Responses Re: Creating server-side functions: one simple error  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Hi,

I have to create my own function in C lanuage, which
will use SPI. The problem that when I had done all things,
PostgreSQL says:
    isbs=# select pgf1test('123');
    ERROR:  Can't find function pgf1test in file /usr/local/pgsql/lib/pgf1test.so

I don't know where problems is. The program is very short, please
point me where my mistake?

pgf1test.c
----------
    #include "executor/spi.h"
    #include <ctype.h>

    Datum           pgf1test(PG_FUNCTION_ARGS);
    PG_FUNCTION_INFO_V1(pgf1test);

    Datum
    pgf1test(PG_FUNCTION_ARGS)
    {
    //      text  tnum = PG_GETARG_NAME(0);
            char *cnum = PG_GETARG_CSTRING(0);
            PG_RETURN_INT32( atoi(cnum) );
    }


compile.sh
----------
    #!/bin/sh

    NAME=pgf1test

    gcc -pipe -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -fpic -DPIC \
        -I. -I/usr/home/rd/postgresql/src/include -c -o ${NAME}.o ${NAME}.c

    /usr/libexec/elf/ld -x -shared -o ${NAME}.so ${NAME}.o
    rm ${NAME}.o

pgf1test-createfunc.sql
-----------------------
    CREATE OR REPLACE FUNCTION pgf1test (text)
            RETURNS int4
            AS '$libdir/pgf1test'
            LANGUAGE 'C' WITH (isStrict);



    All that files worked well - I have created .so object and installed it
    into /usr/local/pgsql/lib/, after that I execute pgf1test-createfunc.sql -
    it's complete successfully, but
        isbs=# select pgf1test('123');
        ERROR:  Can't find function pgf1test in file /usr/local/pgsql/lib/pgf1test.so

show errors. Why PostgreSQL can't found C-function? I know that problem
is not complex, and it's very simple question for you. Thanks.

---
 best regards,
Ruslan A Dautkhanov

pgsql-bugs by date:

Previous
From: Ruslan A Dautkhanov
Date:
Subject: Postmaster crash!
Next
From: Tom Lane
Date:
Subject: Re: Creating server-side functions: one simple error