Thread: I need example of c++ function for postgres

I need example of c++ function for postgres

From
Yuriy Rusinov
Date:
Hello, everyone !

I have developed function for postgresql, compile it, make .so-file and
when I try to link this function to a database it was an error "Cannot
find function weight_ave in <file>.so". Here is code of this function:

weight_ave.h :

#ifndef _WEIGHTAVE_H
#define _WEIGHTAVE_H

double weight_ave (const double* const w, const double* const x, int n);

#endif

weight_ave.cpp:

#include "weight_ave.h"

double weight_ave (const double* const w, const double* const x, int n)
{
    double sumx=0.0;
    double sumw=0.0;
    for (int i=0; i<n; i++)
    {
        sumx+=w[i]*x[i];
        sumw+=w[i];
    }
    return sumx/sumw;
}

what files I have to include and which way I have to declare this
function on include.

Best regards,
Sincerely yours,
Yuriy Rusinov.


Re: I need example of c++ function for postgres

From
s0lao@netscape.net (S. L.)
Date:
Yuriy,

A look at

http://www.postgresql.org/docs/7.3/static/xfunc-c.html

(or xfunc-c.html in your distribution's docs) could offer some help. This is more a general using issue than a cygwin
one.

SLao

__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455

Re: I need example of c++ function for postgres

From
"Henshall, Stuart - TNP Southwest"
Date:

Have a look at http://www.postgresql.org/docs/7.3/interactive/xfunc-c.html
You'll almost certainly want to extern "c" any routines you want to call from postgres (this'll stop C++ name mangaling).

Also this is the pgsql-cygwin list, meant for the cygwin MS Windows version of postgres.
I suspect you'll probably find more help on pgsql-general@postgresql.org
hth,
- Stuart
P.S. Sorry about the format change, the disclaimer adder forces it :(

> -----Original Message-----
> From: Yuriy Rusinov [mailto:rusinov@quasar.ipa.nw.ru]
> Sent: 08 July 2003 13:00
> To: pgsql-cygwin@postgresql.org
> Subject: [CYGWIN] I need example of c++ function for postgres
>
>
> Hello, everyone !
>
> I have developed function for postgresql, compile it, make
> .so-file and
> when I try to link this function to a database it was an
> error "Cannot
> find function weight_ave in <file>.so". Here is code of this function:
>
> weight_ave.h :
>
> #ifndef _WEIGHTAVE_H
> #define _WEIGHTAVE_H
>
> double weight_ave (const double* const w, const double* const
> x, int n);
>
> #endif
>
> weight_ave.cpp:
>
> #include "weight_ave.h"
>
> double weight_ave (const double* const w, const double* const
> x, int n)
> {
>     double sumx=0.0;
>     double sumw=0.0;
>     for (int i=0; i<n; i++)
>     {
>         sumx+=w[i]*x[i];
>         sumw+=w[i];
>     }
>     return sumx/sumw;
> }
>
> what files I have to include and which way I have to declare this
> function on include.
>
> Best regards,
> Sincerely yours,
> Yuriy Rusinov.

DISCLAIMER:The information in this message is confidential and may be legally privileged. It is intended solely for the addressee.  Access to this message by anyone else is unauthorised.  If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful.  Please immediately contact the sender if you have received this message in error. Thank you.