f



Re: pgsql function using C++?, or at least C interfacing with C++ lib?

> -----Original Message-----
> From: pgsql-general-owner@postgresql.org=20
> [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Eric Parusel
> Sent: Saturday, October 16, 2004 4:12 PM
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] pgsql function using C++?, or at least C=20
> interfacing with C++ lib?
>=20
>=20
> Hello,
>=20
> 	I've got a C++ library I need to use, and I want to use=20
> it from a pgsql=20
> function.
> Would anyone happen to have any examples of how to accomplish=20
> something=20
> like this?
> I see examples of C-based functions for pgsql (like dbsize, etc, in=20
> contrib).
>=20
> Which way should I go about this?
>=20
> 1) C based function, calling a C++ library (is this possible?)

If you want to do this, publish an interface in your C++ library with
the interface functions declared as extern "C"

> 2) C++ based function, calling a C++ library (I read in the=20
> pgsql docs=20
> that compiling C++ code for use with pgsql is either partially=20
> incompatible, or just a bad idea?)

C++ calling C++ is not portable because of name mangling.  Other than
that, if you use the same compiler there is rarely any problem.

> Also note that I would like to pass the function the=20
> following arguments: int4, _varchar (array of varchars)
>=20
> Any help would be appreciated, I'm not incredibly experienced=20
> in these=20
> matters.

I would use an extern "C" interface, if I were in your shoes.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

0
DCorbit
10/16/2004 11:21:53 PM
comp.postgresql.general 5128 articles. 0 followers. Post Follow

1 Replies
355 Views

Similar Articles

[PageSpeed] 37

"Dann Corbit" <DCorbit@connx.com> writes:
>> I've got a C++ library I need to use, and I want to use 
>> it from a pgsql function.

> If you want to do this, publish an interface in your C++ library with
> the interface functions declared as extern "C"

Note that the backend does not incorporate any C++ library support,
which is rather a severe handicap.  For instance it will probably
not work to use catch/throw constructs.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

0
tgl
10/17/2004 3:56:58 AM
Reply: