www.digitalmars.com         C & C++   DMDScript  

D - Interfacing with C++

reply "Julio César Carrascal Urquijo" <adnoctum phreaker.net> writes:
The documentation says:

    D does not provide an interface to C++. Since D, however,
    interfaces directly to C, it can interface directly to C++ code
    if it is declared as having C linkage.

I've been looking for this subject on Google but can't find a way to do
this.

I would like to use a C++ cryptography library on a D program.


Thanks

_____________________________

Julio César Carrascal Urquijo
<adnoctum_at_phreaker_dot_net>
May 25 2003
parent Ilya Minkov <midiclub 8ung.at> writes:
Julio C=E9sar Carrascal Urquijo wrote:
 The documentation says:
=20
     D does not provide an interface to C++. Since D, however,
     interfaces directly to C, it can interface directly to C++ code
     if it is declared as having C linkage.
=20
 I've been looking for this subject on Google but can't find a way to do=
 this.
=20
 I would like to use a C++ cryptography library on a D program.
Look at the C++ library. Do the functions you have to use have extern=20 "C"? Or are you using objects to communicate with the library. If there is extern"C", you simply write prototypes in D, which would be=20 almost the same with corrections for type system differencies. You have=20 to prepend extern(c) to prototypes in D, or put them into such a block. Else, you have to write a set of C functions (extern "C") which would=20 call C++ code, and use them from D as in the previous case. While this=20 approach is good where performance is not an important issue (like GUI), = i wouldn't recommend doing that for encryption and other math libraries. = Look for C libraries instead. Maybe a documentation of the library you=20 want to use mentions a corresponding C library if it originates from one.= -i.
May 25 2003