May 25, 2003 Interfacing with C++ | ||||
---|---|---|---|---|
| ||||
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 Re: Interfacing with C++ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Julio César Carrascal Urquijo | Julio César Carrascal Urquijo wrote:
> 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.
Look at the C++ library. Do the functions you have to use have extern "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 almost the same with corrections for type system differencies. You have 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 call C++ code, and use them from D as in the previous case. While this 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 want to use mentions a corresponding C library if it originates from one.
-i.
|
Copyright © 1999-2021 by the D Language Foundation