C function extending postgres - Mailing list pgsql-sql

From Theo Galanakis
Subject C function extending postgres
Date
Msg-id D1444817B78AB546BF2896C2B70E7F04371F84@ganesh.au.lpint.net
Whole thread Raw
Responses Re: C function extending postgres  (Jonathan Daugherty <cygnus@cprogrammer.org>)
List pgsql-sql
<p><font face="Arial" size="2">#include "postgres.h"</font><br /><font face="Arial" size="2">#include
"fmgr.h"</font><br/><font face="Arial" size="2">#include "proc.h"</font><p><font face="Arial"
size="2">PG_FUNCTION_INFO_V1(get_process_total);</font><p><fontface="Arial" size="2">Datum</font><br /><font
face="Arial"size="2">get_process_total(PG_FUNCTION_ARGS)</font><br /><font face="Arial" size="2">{</font><br />       
<fontface="Arial" size="2">float ret;</font><br />        <font face="Arial" size="2">ret = proc_cpu_user() +
proc_cpu_nice()+ proc_cpu_system() - proc_cpu_idle();</font><br />        <font face="Arial"
size="2">PG_RETURN_FLOAT4(ret);</font><br/><font face="Arial" size="2">}</font><p><font face="Arial" size="2">Hi
,</font><p>       <font face="Arial" size="2">I'm getting the following error when attempting to call the above
function,I have included the -I path when compiling, and have compiled a similar function to execute and printf to
linuxwithout a problem :</font><p><font face="Arial" size="2">Returned by postgres:</font><br />        <br />       
<fontface="Arial" size="2">ERROR:  could not load library "/usr/lib/pgsql/processinfo.so":
/usr/lib/pgsql/processinfo.so:undefined symbol: proc_cpu_idle</font><p><font face="Arial" size="2">Compiling:</font><br
/>       <font face="Arial" size="2">cc -g -I /usr/local/pgsql/include -I /usr/local/pgsql/include/server -I
/usr/local/include-fpic -c processinfo.c</font><p>        <font face="Arial" size="2">cc -g -I /usr/local/pgsql/include
-I/usr/local/pgsql/include/server -I /usr/local/include -shared -o processinfo.so processinfo.o</font><p><font
face="Arial"size="2">Here is the postgres create function:</font><br /><font face="Arial" size="2">CREATE FUNCTION
get_process_total()RETURNS float4</font><br /><font face="Arial" size="2">    AS '$libdir/processinfo',
'get_process_total'</font><br/><font face="Arial" size="2">LANGUAGE 'c' STABLE STRICT;</font><p><font face="Arial"
size="2">TEST:</font><br/><font face="Arial" size="2">select * from get_process_total()</font><p><font face="Arial"
size="2">Yourhelp would be greatly appreciated.</font><p><font face="Arial" size="2">Theo</font><table><tr><td
bgcolor="#ffffff"><fontcolor="#000000">______________________________________________________________________<br />
Thisemail, including attachments, is intended only for the addressee<br /> and may be confidential, privileged and
subjectto copyright. If you<br /> have received this email in error, please advise the sender and delete<br /> it. If
youare not the intended recipient of this email, you must not<br /> use, copy or disclose its content to anyone. You
mustnot copy or <br /> communicate to others content that is confidential or subject to <br /> copyright, unless you
havethe consent of the content owner.<br /></font></td></tr></table> 

pgsql-sql by date:

Previous
From: "Sean Davis"
Date:
Subject: Re: "Flattening" query result into columns
Next
From: Jonathan Daugherty
Date:
Subject: Re: C function extending postgres