Extending PostgreSQL in C or C++

From: Sebastien Lemieux <slemieux(at)elitra(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Extending PostgreSQL in C or C++
Date: 2003-06-17 20:36:08
Message-ID: Pine.LNX.4.33.0306171627570.25045-100000@moebius.elitra.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I need to extend postgreSQL to support some specific function I will
code in C (ideally C++ if it can work!). I'm trying to run some simple
test and it doesn't seem to work. Here is the C code:

----------
#include "postgres.h"
#include <string.h>

int
add_one(int arg)
{
return arg + 1;
}
----------

Which is compiled with:
gcc -fpic -c -I/[ThePath]/postgresql-7.3.2/include/server/ pgsql_bio.c
gcc -shared -o pgsql_bio.so pgsql_bio.o

It compiles fine.

And then in postgreSQL as user postgres in database template1:
CREATE FUNCTION add_one(int4) RETURNS int4
AS '/[PathToTheObject]/pgsql_bio.so' LANGUAGE C
WITH (isStrict);

Then I get:
ERROR: Can't find function add_one in file /[PathToTheObject]/pgsql_bio.so

I'm using PostgreSQL 7.3.2 on Redhat 7.2 (linux 2.4.7-10) and compiling
with gcc 2.95.3.

Following some suggestions I found on usenet, I ran 'nm' on the library
and I got the expected entry for my function:
00000700 T add_one

Anyone has an idea about what I am doing wrong? Any suggestion will be
welcome!

thanks,

--
Sebastien Lemieux
Bioinformatics, post-doc
Elitra-canada

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kurt Roeckx 2003-06-17 20:49:00 Re: ss_family in hba.c
Previous Message Bruno Wolff III 2003-06-17 20:32:32 ss_family in hba.c