Thread: postgres functions and C++
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.somy=> What is wrong ? I'm using postgres 6.4 under RedHat. Any help will be appreciated. -- Best regards,Vladimir mailto:gsmith@eurocom.od.ua
"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
"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