Hello all,

Please help me with
create function days_in_month(int4, int4, int4) returns int4
as '/tmp/days.so' language 'c';

Can I write this function days_in_month in C++ ?
I've did the following:

extern "C" {
int days_in_month(int year, int mo, int day); 
} 

extern "C" { 
int days_in_month(int year, int mo, int day) { 
О©╫О©╫О©╫ return 13;
} 
} 

Compile with
  $ g++ -I/usr/local/qt/include -o days.so -shared days.cpp

then (as user postgres)
  my=> create function days_in_month(int4, int4, int4) returns int4
  my=> as '/tmp/days.so' language 'c';
  CREATE
  
I've tried to use new function
  my=> select days_in_month(3, 3, 3);
  ERROR:О©╫ Can't find function days_in_month in file /tmp/days.so
  my=>
  
What is wrong ?
I'm using postgres 6.4 under RedHat.
Any help will be appreciated.

-- 
Best regards,
 Vladimir                          mailto:gsmith@eurocom.od.ua



Wed, 4 Oct 2000 12:59:06 +0400
"Vladimir V. Zolotych" <gsmith@eurocom.od.ua>
postgres functions and C++
"Vladimir V. Zolotych" <gsmith@eurocom.od.ua> writes:
>   my=> select days_in_month(3, 3, 3);
>   ERROR: Can't find function days_in_month in file /tmp/days.so

Try using 'nm' to see what symbol name is actually being exported
from the .so file.  I suspect that despite your use of extern "C",
your C++ compiler is being uncooperative and is naming the function
in some strange fashion at the link level.

There is an option in CREATE FUNCTION to specify the link symbol
name separately from the SQL name of the function, so if you can't
get your compiler to play nice you could still get it to work by
quoting whatever nm tells you...

			regards, tom lane

Wed, 04 Oct 2000 11:29:48 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: postgres functions and C++ 
"Vladimir V. Zolotych" wrote:

> Hello all,
>
> Compile with
>   $ g++ -I/usr/local/qt/include -o days.so -shared days.cpp

IIRC you have to compile as days.o and then link to .so:
g++ .... -o days.o
ld -shared -o days.so days.o

I don't know if the compiler gets it right in one line. It might.

Christof



Sat, 07 Oct 2000 23:19:23 +0200
Christof Petig <christof.petig@wtal.de>
Re: postgres functions and C++