pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Calling C++ function
3+ messages / 3 participants
[nested] [flat]

* Calling C++ function
@ 2004-08-13 12:40 Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de>
  2004-08-15 18:27 ` Re: Calling C++ function Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Oliver Archner @ 2004-08-13 12:40 UTC (permalink / raw)
  To: pgsql-interfaces

Hi,

i'm trying to write a user-defined C function which creates a thumbnail 
out of a base64 encoded string. The ImageMagick C++ API provides exactly 
the functionality i need. So i would like to use these C++ functions.
I figured out that i have to define the entry point function with C
linkage (extern "C" { ... }).
Can anyone point me to example which calls a C++ function from a dynamic 
library ?

-- 
Oliver Archner
Tel.: 0921/55-5727
Fax.: 0921/55-5799
BITÖK Wissenschaftliches Sekretariat
Universität Bayreuth
D-95440 Bayreuth




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Calling C++ function
  2004-08-13 12:40 Calling C++ function Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de>
@ 2004-08-15 18:27 ` Tom Lane <tgl@sss.pgh.pa.us>
  2004-08-15 20:35   ` Re: Calling C++ function Richard Welty <rwelty@averillpark.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2004-08-15 18:27 UTC (permalink / raw)
  To: Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de>; +Cc: pgsql-interfaces

Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de> writes:
> Can anyone point me to example which calls a C++ function from a dynamic 
> library ?

It's gonna be fairly painful, since the backend is a C program not a C++
program, and therefore it does not provide any of the infrastructure
that C++ code is likely to expect --- no exception stack, no global
constructors/destructors, no C++ library, etc.  I am not sure how much
of this is practical to load after-the-fact in a dynamic library.

My inclination if you really need to use ImageMagick would be to shell
out to the IM executable via system() (or better popen(), if you have a
modern popen that supports 'r+' access).

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Calling C++ function
  2004-08-13 12:40 Calling C++ function Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de>
  2004-08-15 18:27 ` Re: Calling C++ function Tom Lane <tgl@sss.pgh.pa.us>
@ 2004-08-15 20:35   ` Richard Welty <rwelty@averillpark.net>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Welty @ 2004-08-15 20:35 UTC (permalink / raw)
  To: pgsql-interfaces

On Sun, 15 Aug 2004 14:27:38 -0400 Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de> writes:
> > Can anyone point me to example which calls a C++ function from a dynamic 
> > library ?

> It's gonna be fairly painful, since the backend is a C program not a C++
> program, and therefore it does not provide any of the infrastructure
> that C++ code is likely to expect --- no exception stack, no global
> constructors/destructors, no C++ library, etc.  I am not sure how much
> of this is practical to load after-the-fact in a dynamic library.

it can probably be pulled off. it will probably be very annoying to do.
we used to call gnu C++ from a Lucid Common Lisp environment back
at GE R&D (i was responsible for that particular integration can of
worms, it brings back painful memories, and it probably was a major
factor in my continuing dislike for C++.)

the library loads and initialization are an issue, as is figuring out the
"C Name" of the C++ functions. we used to run nm over the C++ object
files to find out what the C++ name mangler did. it was very clumsy,
and i spent a lot of time wishing for a better method.

tom's suggestion of shelling out might be a lot less painful.

richard
-- 
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
    Java, PHP, PostgreSQL, Unix, Linux, IP Network Engineering, Security




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-08-15 20:35 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-08-13 12:40 Calling C++ function Oliver Archner <oliver.archner@bitoek.uni-bayreuth.de>
2004-08-15 18:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-08-15 20:35   ` Richard Welty <rwelty@averillpark.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox