Обсуждение: Calling C++ function

Поиск
Список
Период
Сортировка

Calling C++ function

От
Oliver Archner
Дата:
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



Re: Calling C++ function

От
Tom Lane
Дата:
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


Re: Calling C++ function

От
Richard Welty
Дата:
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