Calypso: Direct and full interfacing to C++

Elie Morisse via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Jan 22 08:06:30 PST 2015


On Thursday, 22 January 2015 at 07:27:03 UTC, Suliman wrote:
> "First you need a LLVM + Clang 3.5 source tree, built libraries 
> and the Clang binaries. Installing binary packages from your 
> distribution isn't enough since the include/ files aren't 
> exposing many symbols, so the source packages are needed as 
> well"
>
> Do I need to compile from source just Clang or both?

Usually Clang is built with LLVM, i.e running make inside the 
LLVM build directory will build both LLVM and Clang.

On Thursday, 22 January 2015 at 07:07:42 UTC, Suliman wrote:
>> Currently making D classes derive from C++ classes with a 
>> virtual table only works with MinGW because only the Itanium 
>> ABI is supported. I'm going to add the Microsoft ABI ASAP 
>> (it's just a few lines of code) but it'll be untested.
>
> Could you explain can I call function from C++ dll directly? I 
> am
> need only basic C++ support -- just ability to call very basic
> functions.
>
> Am I right understand that with Calypso I do not need to create
> bindings?
>
> If it's correct - could you provide any example of calling C++
> function from dll?

On Windows the Clang executable has to be in one of the %PATH% 
folders and then in your D code:

   modmap (C++) "headerofyourdll.h"; // will make Clang generate a 
precompiled header

   import (C++) Namespace1.Namespace2._; // If your functions are 
global functions inside Namespace1.Namespace2, _ is a special 
module (for now) that contains all the global funcs, vars and 
typedefs
   import (C++) Namespace1.Struct1; // If they are inside a struct 
named Struct1

The imports expose symbols that you can use like you'd use D 
structs and functions.

Finally you need to tell LDC to link to your library:

   ldc -L="yourDLL.lib" (...)


More information about the Digitalmars-d-announce mailing list