Extending PostgreSQL in C or C++ - Mailing list pgsql-hackers

From Sebastien Lemieux
Subject Extending PostgreSQL in C or C++
Date
Msg-id Pine.LNX.4.33.0306171627570.25045-100000@moebius.elitra.com
Whole thread Raw
Responses Re: Extending PostgreSQL in C or C++  (David Blasby <dblasby@refractions.net>)
Re: Extending PostgreSQL in C or C++  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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



pgsql-hackers by date:

Previous
From: Bruno Wolff III
Date:
Subject: ss_family in hba.c
Next
From: Kurt Roeckx
Date:
Subject: Re: ss_family in hba.c